GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bug: PDF 改ページが過剰(見出し中身が少なくても次ページに飛ぶ)の調査と修正 · Issue #93 · ymnao/scripta

bug: PDF 改ページが過剰(見出し中身が少なくても次ページに飛ぶ)の調査と修正 #93

New issue
Copy link
New issue
Copy link
Closed
#131
Closed
bug: PDF 改ページが過剰(見出し中身が少なくても次ページに飛ぶ)の調査と修正#93
#131
Copy link
Labels
bugSomething isn't working
Milestone
v0.2.0

Description

@ymnao
ymnao
opened on May 28, 2026
Issue body actions

親 #81 の Phase 4 (#86) 完了後に再現確認のうえ着手。

本 Issue は 調査型: 仮説検証 → 根本原因特定 → 修正 を 1 PR で行う。原因が複数判明したら子 Issue に分割。

現象

PDF エクスポート時、見出し直後のコンテンツが少なく明らかに現ページに収まるサイズでも、見出しが次ページ頭へ強制改ページされる。

想定原因(仮説リスト)

src/lib/export.ts:225-383 の buildDynamicPageBreakScript で動的に DOM 計測して改ページを決定している。仮説:

仮説 1: safetyBuffer が cross-WebView 想定で過剰

src/lib/export.ts:278-280:

var safetyBuffer = lineRuler.getBoundingClientRect().height;
var safePageHeight = pageHeight - safetyBuffer * 3;

3 行分のマージンは macOS WKWebView / Windows WebView2 / Linux WebKitGTK の累積レイアウト誤差を吸収する保守的な値。Chromium 固定の Electron では誤差が小さいため * 3 が大きすぎ、結果として safePageHeight が過小評価されて改ページが早く発動している可能性。

検証: * 3 を * 1 に変更して再現有無を確認。

仮説 2: zoom 補正の計算ズレ

src/lib/export.ts:236:

var zoom = parseFloat(document.body.style.zoom) || 1;
var pageHeight = ruler.getBoundingClientRect().height / zoom;

zoom 適用時の getBoundingClientRect() の挙動が WebView ごとに微妙に異なる前提で補正していたが、Chromium で過補正になっている可能性。

検証: zoom 1.0(補正不要)でも症状が出るか確認。

仮説 3: minNeeded の 2 ブロック先読みが過剰

src/lib/export.ts:347-353:

var minNeeded = h;
var extra = 0;
for (var k = i + 1; k < items.length && extra < 2; k++) {
  if (items[k].tagName.match(/^H[1-6]$/)) break;
  minNeeded += heights[k];
  extra++;
}

見出し + 直後 2 ブロックの高さを要求しているが、2 ブロック目が長い段落だった場合に過剰要求になる。

検証: extra < 1 に変更して再現有無を確認。

仮説 4: 画像 / Mermaid / KaTeX の高さ計測タイミング

スクリプトが走るタイミングで画像未ロード / Mermaid 未描画 / KaTeX 未レンダーだと高さ 0 として計測される可能性。これは Phase 2 の Mermaid thin 化と連動する可能性あり。

検証: 画像 / 数式 / Mermaid のないシンプルな markdown で再現するか確認。

調査手順

  1. 最小再現サンプル作成: 「見出し + 短い段落 1 行」だけの .md で PDF 出力
  2. 仮説 1 検証: safetyBuffer * 3 → * 1 で再現有無
  3. 仮説 3 検証: extra < 2 → extra < 1 で再現有無
  4. 仮説 2 検証: zoom 1.0 で再現有無
  5. 仮説 4 検証: 画像なし markdown で再現有無
  6. 原因特定後、修正を実装

関連する Tauri purge との連動

  • Phase 2 で Mermaid を thin 化した結果、Mermaid 含む PDF の高さ計測タイミングが改善する可能性
  • Phase 6 で TS target が ESNext になることでビルド差異が出る可能性は低い
  • → 親 refactor: Tauri レガシー完全除去(トラッカー) #81 完了後の再現確認で残存していたら本 Issue を着手

受け入れ基準

  • 最小再現サンプル .md が Issue 本文 or e2e/fixtures/ に添付
  • 根本原因が特定され Issue にコメント記録
  • 修正後、再現サンプルが期待通りページに収まる
  • 既存の改ページ挙動(長い文書での見出し改ページ等)に regression なし
  • pnpm test 全 pass(PDF export 関連のユニットテストがあれば update)
  • 手動 QA: 既存の長文ドキュメント数件で PDF 出力 → 妥当な改ページ

スコープ外

  • 既存 Issue fix: PDF export の KaTeX CSS CDN URL が古いバージョンで固定 (export.ts:412) #79(KaTeX CDN URL 古い)→ 別 Issue で対応
  • safetyBuffer チューニングは Phase 6 ではなく本 Issue で扱う

関連

  • 親 Tauri purge: refactor: Tauri レガシー完全除去(トラッカー) #81
  • 既存 fix: PDF export の KaTeX CSS CDN URL が古いバージョンで固定 (export.ts:412) #79(KaTeX CDN URL 古い、export 系の別バグ)

Activity

  1. ymnao
    added this to the v0.2.0 milestone on May 28, 2026
  2. ymnao
    added
    bugSomething isn't working
    on May 28, 2026
  3. ymnao
    added 3 commits that reference this issue on Jun 2, 2026

    fix: PDF / editor の Mermaid ラベル消失・サイズ過大を 6 層 defense で解消 (#106) (#130)

    9732860

    test(e2e): export.spec.ts を PDF default に追従 + PDF タブ strict-mode 修正 (#93

    3952b85

    fix: PDF 改ページの過剰問題を hybrid 設計で解消 (#93) (#131)

    42a1036
  4. ymnao
    closed this as completedin #131on Jun 3, 2026
  5. ymnao
    added 2 commits that reference this issue on Jun 7, 2026

    docs: exploratory-qa の KaTeX CDN 既知バグ記述を更新

    8a0a928

    feat: KaTeX CSS/font 完全オフライン化 + tmp 脆弱性解消 (#145)

    522b79b
  6. ymnao
    added a commit that references this issue on Jul 14, 2026

    feat: スライド PDF エクスポート機能を追加 (#329)

    5993ea0
  7. ymnao
    added a commit that references this issue on Nov 12, 2026

    fix(deps): fast-uri を 3.1.9 へ上げ、minimatch の advisory を許容として記録する (#748)

    a89de0e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      • v0.2.0No due date

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.