Skip to content

fix(export): prevent blank pages before tall Mermaid diagrams - #21328

Closed
innocarpe wants to merge 2 commits into
stablyai:mainfrom
innocarpe:fix/pdf-mermaid-blank-page
Closed

innocarpe wants to merge 2 commits into
stablyai:mainfrom
innocarpe:fix/pdf-mermaid-blank-page

Conversation

@innocarpe

Copy link
Copy Markdown
Contributor

What this changes

Mermaid diagrams in exported Markdown PDFs now receive a printable-height limit in print media. The limit preserves the SVG aspect ratio while allowing a diagram taller than the A4 content area to scale down instead of forcing the browser to move it to a new page and leave a blank page behind the preceding heading.

Why

webContents.printToPDF() uses A4 paper with 0.75-inch margins, leaving a printable height of about 10.19 inches. Export CSS already avoids breaking inside SVGs and constrains their width, but an unusually tall Mermaid SVG could fit on no page. The heading's page-break-after: avoid then made the page before the diagram completely blank.

Linked issue

Fixes #21310

Testing

  • pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/components/editor/markdown-export-html.test.ts
  • pnpm run typecheck:web
  • ORCA_CODE_QUALITY_BASE=upstream/main pnpm run check:code-quality:changed
  • pnpm exec oxfmt --check src/renderer/src/components/editor/export-css.ts src/renderer/src/components/editor/markdown-export-html.test.ts

AI disclosure

Implemented with AI assistance and reviewed against the existing PDF export margins and stylesheet behavior.

Checklist

  • The change is focused and preserves existing export behavior for diagrams that fit on a page.
  • A regression test covers the printable-height CSS rule.
  • No UI screenshot is applicable; this is PDF print layout behavior.
  • Cross-platform impact is limited to Chromium print CSS and the existing Electron PDF export path.

@coderabbitai

coderabbitai Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Important

Review skipped

We couldn't safely recover the incremental review. No full review was started, and the last reviewed checkpoint was preserved. Retry later, or explicitly request a full review by commenting @coderabbitai full review.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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: 287582c1-945b-4ddf-a9e6-fe2877f11c8b

📥 Commits

Reviewing files that changed from the base of the PR and between b23564646cd117ea137c23823e06560b3d23d363 and 6581aeeda0bb0e78664cb09aaa009d38938ecb8e.

📒 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; 1 remains after this review.

Walkthrough

The print stylesheet now limits .orca-export-root svg height to 9.5in within the @media print block. Existing page-break rules remain unchanged. A test verifies that buildMarkdownExportHtml includes the new CSS rule.

Priority: Normal

Severity of issue fixed: Medium

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: preventing blank pages before tall Mermaid diagrams during export.
Description check ✅ Passed The description explains the user impact, technical change, reason, linked issue, testing, AI use, and cross-platform scope. It omits several template headings, including ELI5, Visual Proof, Review, A…
Linked Issues check ✅ Passed The PR meets the coding requirements in issue #21310. export-css.ts keeps max-width: 100% and height: auto, and adds .orca-export-root svg { max-height: 9.5in; } inside @media print. The 9.5…
Out of Scope Changes check ✅ Passed The changes stay within issue #21310. The production change limits exported SVG height during print-to-PDF export. The added test verifies that export CSS. No unrelated changes appear in the reviewed …
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…
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@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 — the fix works. Minor suggestions inline.

Reviewed changes

  • Print-only SVG height cap — adds .orca-export-root svg { max-height: 10.19in; } to the @media print block in export-css.ts, capping tall Mermaid SVGs to the A4 printable box so they can be placed on a page instead of forcing a blank page before the preceding heading.
  • Regression test — asserts the literal rule string is present in the built export HTML.

I reproduced the original bug and confirmed the fix in headless Chromium with the real EXPORT_CSS, A4 plus 0.75in margins: the uncapped stylesheet produced blank pages, the capped one produced none, and the rendered drawing kept its viewBox aspect ratio exactly (no squash). One note on the chosen cap value is inline.

ℹ️ Nitpicks

  • The test at markdown-export-html.test.ts:39 matches the rule as an exact, whitespace-sensitive string and cannot exercise print layout. That mirrors the file's existing style, so it's optional, but asserting the rule sits inside the @media print block (or matching a looser pattern) would let it survive reformatting.
  • The same page-break-inside: avoid path applies to img, pre, and table; a portrait image taller than the page reproduces the blank-page bug. Out of scope for this issue, but worth a follow-up if tall images show the same symptom.

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

@innocarpe
innocarpe force-pushed the fix/pdf-mermaid-blank-page branch from b235646 to 6581aee Compare September 18, 2026 02:51
@innocarpe

Copy link
Copy Markdown
Contributor Author

Sync update (6581aeeda)

Adjusted the Mermaid PDF cap to 9.5in so the preceding heading retains printable space and cannot strand a heading-only page.

@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

  • Lowered the print SVG cap — export-css.ts:143 now uses max-height: 9.5in instead of 10.19in, reserving roughly 0.69in so a preceding heading can share the page with a tall diagram rather than being orphaned onto a heading-only page.
  • Documented the cap derivation — the comment now states that A4 minus the PDF margins is 10.19in, so the value tracks the geometry owned by src/main/lib/html-to-pdf.ts:67.
  • Updated the regression test — asserts the new literal rule string, consistent with the file's existing assertions.

The change directly addresses the prior inline note: 9.5in was the measured value that kept each heading with its diagram in the headless-Chromium repro, and the reasoning is now in the comment. The mechanism is unchanged from what was already validated, so no new review of the rendering behavior was needed.

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

@innocarpe
innocarpe force-pushed the fix/pdf-mermaid-blank-page branch 3 times, most recently from 21a33bb to b12ac04 Compare October 22, 2026 00:12
@innocarpe
innocarpe force-pushed the fix/pdf-mermaid-blank-page branch from b12ac04 to 203077d Compare October 29, 2026 10:16
@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[Low impact] Adjusts print styling for exported diagrams.

The PR should not merge until the height cap reliably accommodates the preceding heading in the pagination case it is intended to fix.

Findings

  1. P1 Heading Space Is Insufficient ▶

Summary

This PR adds a print-media height limit for exported SVGs to scale tall Mermaid diagrams within an A4 PDF page and adds a regression assertion for the generated stylesheet.

  • Applies a 9.5-inch maximum SVG height during printing.
  • Retains the existing SVG aspect-ratio and page-break rules.
  • Adds a unit test confirming that the new CSS is embedded in export HTML.
  • The reserved space is insufficient for larger heading styles, leaving the targeted pagination case incomplete.

Reviews (1) · Last reviewed commit: "fix(export): leave room for PDF diagram ..." · Reviewed by Greptile

@media print {
pre, code, table, img, svg { page-break-inside: avoid; }
/* Why: A4 minus the PDF margins is 10.19in, so reserve heading space to keep a tall diagram on its page. */
.orca-export-root svg { max-height: 9.5in; }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Heading space is insufficient

The 9.5-inch cap leaves only 0.69 inches of the 10.19-inch printable area for the preceding heading. The existing heading styles require more space for common headings: a one-line h1, for example, occupies about 1.2 inches including its margins. A maximum-height diagram therefore still cannot share a page with an h1, h2, or h3 despite page-break-after: avoid, so Chromium may separate the heading or reproduce the blank-page pagination this change is intended to prevent. Reserve enough space for the largest supported heading and test the combined heading-and-diagram layout rather than only the CSS string.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

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