Skip to content

fix(editor): cap printed diagram height so a tall one cannot blank a page - #21377

Closed
gum798 wants to merge 2 commits into
stablyai:mainfrom
gum798:fix/pdf-export-tall-diagram-blank-page
Closed

gum798 wants to merge 2 commits into
stablyai:mainfrom
gum798:fix/pdf-export-tall-diagram-blank-page

Conversation

@gum798

@gum798 gum798 commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

ELI5

When exporting Markdown to PDF, really tall diagrams (like long flowcharts) no longer create completely blank pages right before them or get cut in half across multiple pages.

What Changed

  • Before: In Markdown PDF export, diagrams had max-width: 100% but no height constraint. When a diagram exceeded the printable height of a page (~978px for A4 with 0.75in margins), page-break-inside: avoid on <svg> and page-break-after: avoid on the preceding heading pushed both onto a new page, leaving the preceding page completely empty. The diagram was also clipped and split across multiple pages.
  • After: Added max-height: 90vh to .orca-export-root img, .orca-export-root svg inside the @media print block in export-css.ts. In paged media (Chromium print), vh resolves to the page box. The 90vh ceiling leaves room for the heading and surrounding margins, scaling the diagram down cleanly onto a single page without blanking the preceding page.
  • Mechanism: Capped printed image and SVG height inside @media print so that oversized blocks scale proportionately within the paged layout box.

Why

  • max-width: 100% was already present to handle wide diagrams; this adds the matching vertical constraint for tall diagrams.
  • Alternatives considered:
    • Allowing page breaks inside diagrams: diagrams split and get truncated across pages, making text and connector lines unreadable.
    • Hardcoding pixel values: fragile across different paper sizes or margin settings. 90vh uses Chromium's paged media viewport resolution, adapting cleanly to the page box.

Linked Issue

Fixes #21310

Visual Proof

Measured with a real Electron printToPDF test harness using the app's exact export options (A4, 0.75in margins) with a 1500px-tall diagram placed immediately behind a heading:

Version Page Count Result
Before 5 pages Page 5 is completely blank; diagram is truncated and split across pages 2–4
After 2 pages No blank pages; both top and bottom labels of diagram present and intact on page 2

Testing

  • Unit test added in src/renderer/src/components/editor/markdown-export-html.test.ts verifying that max-height: 90vh is included inside @media print.
  • pnpm test src/renderer/src/components/editor/markdown-export-html.test.ts — 5 tests passed.
  • pnpm tc:web — clean.
  • node config/scripts/check-changed-code-quality.mjs upstream/main — 0 findings across all scans (oxlint, design system, type-aware, casting SAFETY).

AI Disclosure

Co-authored with Claude Opus 5 and Antigravity (Gemini).

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A) — CSS export stylesheet change only, identical across all platforms
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

…page

The export prints A4 with 0.75in margins, leaving about 978px of printable
height, but the stylesheet capped only width. A Mermaid diagram taller than
that fit nowhere: `page-break-inside: avoid` kept the svg whole and the
preceding heading's `page-break-after: avoid` dragged the heading onto the new
page too, so the page they left behind came out fully blank -- and the diagram
itself was clipped across the pages it spilled over.

Cap svg and img height in the print block. Measured against the real print
options with a 1500px-tall diagram behind a heading: before, 5 pages with the
last blank and the diagram split across three; after, 2 pages, no blank, and
both ends of the diagram present.

Fixes stablyai#21310

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01T6zUCU6cyicLSBNzHWQnh4
@coderabbitai

coderabbitai Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: c2c63b41-d9e5-4498-a410-585becd46aad

📥 Commits

Reviewing files that changed from the base of the PR and between e78d2d3 and afd441c.

📒 Files selected for processing (2)
  • src/renderer/src/components/editor/export-css.ts
  • src/renderer/src/components/editor/markdown-export-html.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/renderer/src/components/editor/markdown-export-html.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The export CSS now limits .orca-export-root images and SVGs to max-height: 90vh and applies object-fit: contain inside @media print. The HTML export test verifies both declarations within the print media query.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to afd44

Exported diagrams are constrained to the printable height while preserving their proportions, reducing blank pages and clipping. No concrete merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: limiting printed diagram height to prevent blank pages.
Description check ✅ Passed The description is mostly complete and directly explains the user impact, implementation, rationale, linked issue, visual results, and testing. It does not include the template's Review, Agent skill u…
Linked Issues check ✅ Passed Issue #21310 requires a printable-height constraint for oversized Mermaid diagrams, no blank pages, and preserved proportions. The print stylesheet adds max-height: 90vh to exported img and svg …
Out of Scope Changes check ✅ Passed The pull request changes only the print stylesheet and its focused test. The stylesheet change implements issue #21310. The test validates the required print rules. No unrelated changes are identified…
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 80c6cbdb-30fc-46cd-86dc-9929ef3d0b3b

📥 Commits

Reviewing files that changed from the base of the PR and between b7d694f and e78d2d3.

📒 Files selected for processing (2)
  • src/renderer/src/components/editor/export-css.ts
  • src/renderer/src/components/editor/markdown-export-html.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No critical issues — minor suggestions inline.

Reviewed changes

  • Print-only height cap for diagrams — adds max-height: 90vh for .orca-export-root img, .orca-export-root svg inside @media print in export-css.ts, so a diagram taller than the A4 page area scales down instead of overflowing and blanking the preceding page.
  • Regression test — asserts the max-height: 90vh declaration is present after the @media print marker in the generated export HTML.

ℹ️ Nitpicks

  • export-css.ts:147 — the comment says vh resolves to "the page box"; in paged media it resolves to the page area (page box minus margins). The arithmetic is right (90vh ≈ 881px against a ~979px printable height), only the term is imprecise.
  • markdown-export-html.test.ts:44 — html.indexOf('max-height: 90vh') > html.indexOf('@media print') still passes if the @media print block is removed entirely (indexOf returns -1), and also for a rule placed after the block. Asserting against the extracted media-block substring would actually pin the print scope.
  • The blank-page mechanism this PR describes (a page-break-inside: avoid block taller than the page area, preceded by a page-break-after: avoid heading) also applies to tall pre/table blocks, which remain uncapped. Worth a follow-up if that is in scope.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

- Add object-fit: contain to printed images and SVGs so a tall raster image with an explicit width scales proportionately rather than stretching.

- Match rules directly within the @media print block in markdown export HTML unit tests to ensure assertions guard the print-only scope.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

Reviewed the delta since the prior pullfrog review (e78d2d3 → afd441ce), three follow-ups to the print-media height cap.

  • Comment terminology corrected — export-css.ts now states vh resolves to the "page area" rather than the "page box".
  • object-fit: contain added — the print rule for .orca-export-root img, .orca-export-root svg now preserves aspect ratio for tall raster images with explicit widths that the height cap would otherwise stretch. It is inert for auto-width images (box already matches the intrinsic ratio) and for inline <svg>.
  • Test scope tightened — the regression test now extracts the @media print block and asserts both declarations live inside it, replacing the indexOf ordering check that could pass with the block removed.

The prior inline thread on raster aspect-ratio distortion was replied to and resolved.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

nwparker added a commit that referenced this pull request Oct 31, 2026
Keep the existing copy button and annotation wrapper while checking the original HAST code class. This removes the extra empty page reproduced in Markdown Preview PDF export without shrinking labels.

Credit gum798 for #21310 and #21377, innocarpe for #21328, and m13v for the label-readability review. The height-cap proposals were evaluated but this fix keeps the existing diagram sizing.
nwparker added a commit that referenced this pull request Oct 31, 2026
Keep the existing copy button and annotation wrapper while checking the original HAST code class. This removes the extra empty page reproduced in Markdown Preview PDF export without shrinking labels.

Credit gum798 for #21310 and #21377, innocarpe for #21328, and m13v for the label-readability review. The height-cap proposals were evaluated but this fix keeps the existing diagram sizing.
nwparker added a commit that referenced this pull request Nov 1, 2026
* Render Mermaid Preview outside its code pre wrapper

Keep the existing copy button and annotation wrapper while checking the original HAST code class. This removes the extra empty page reproduced in Markdown Preview PDF export without shrinking labels.

Credit gum798 for #21310 and #21377, innocarpe for #21328, and m13v for the label-readability review. The height-cap proposals were evaluated but this fix keeps the existing diagram sizing.

* fix(editor): keep a diagram's copy button beside its expand button

Trim the wrapper test to the regression cases and mock the runtime target hook main now uses.
@nwparker

nwparker commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Thanks for this. The blank page before a tall Mermaid diagram was fixed in #25621 by removing the extra <pre> wrapper that added a print boundary around the SVG, which leaves diagrams at full size. We tested a height cap through the real export, and it shrank large diagrams until their labels couldn't be read, so we went with the wrapper fix. Closing as superseded; your report and approach are credited in #25621.

@nwparker nwparker closed this Nov 1, 2026
creitimfuba pushed a commit to creitimfuba/orca that referenced this pull request Nov 9, 2026
Keep the existing copy button and annotation wrapper while checking the original HAST code class. This removes the extra empty page reproduced in Markdown Preview PDF export without shrinking labels.

Credit gum798 for stablyai#21310 and stablyai#21377, innocarpe for stablyai#21328, and m13v for the label-readability review. The height-cap proposals were evaluated but this fix keeps the existing diagram sizing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: PDF export slices Mermaid diagrams taller than the page and can strand their heading

2 participants