Skip to content

fix: print as PDF renders blank page#124

Merged
erictli merged 4 commits intoerictli:mainfrom
jordanlee:fix/print-as-pdf
Apr 3, 2026
Merged

fix: print as PDF renders blank page#124
erictli merged 4 commits intoerictli:mainfrom
jordanlee:fix/print-as-pdf

Conversation

@jordanlee
Copy link
Copy Markdown
Contributor

@jordanlee jordanlee commented Mar 28, 2026

Summary

  • Fix print as PDF rendering a blank page by using a dedicated preview window with proper content loading
  • Improve print margins and page styling for clean PDF output
  • Swap shortcuts: Cmd+P → command palette (standard), Cmd+Shift+P → print/export as PDF
  • Block browser print dialog in preview mode
  • Add print shortcut to Settings > Shortcuts reference

Test plan

  • Print a note via Cmd+Shift+P — PDF renders with correct content and margins
  • Cmd+P opens command palette in main app
  • Cmd+P is blocked in preview mode (no browser print dialog)
  • Verified with a clean (non-cached) build

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • New Features

    • Added keyboard shortcut (Cmd/Ctrl+Shift+P) to print and export notes as PDF.
  • Improvements

    • Enhanced print/PDF layout with optimized margins, width constraints, and page-break handling.
    • Improved table and editor styling for print output.
    • Better sidebar and toolbar visibility management in print view.

Two issues caused Print as PDF to produce a blank page:

1. The editor scroll container uses absolute positioning (absolute inset-0)
   which collapses to zero height when print styles set the parent to
   height: auto. Fixed by adding data-editor-content-area and
   data-editor-scroll attributes and overriding to position: static in
   the print media query.

2. The sidebar-hiding rule (#root > div > div:first-child) also hid the
   entire editor in preview mode (files opened directly in Scratch),
   where the editor is the first child. Fixed by targeting a [data-sidebar]
   attribute instead of :first-child.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 28, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 380fa576-7cdd-4427-a447-3ca1cb212f6b

📥 Commits

Reviewing files that changed from the base of the PR and between 77d2963 and f4334d0.

📒 Files selected for processing (6)
  • src/App.css
  • src/App.tsx
  • src/components/editor/Editor.tsx
  • src/components/preview/PreviewApp.tsx
  • src/lib/shortcuts.ts
  • src/services/pdf.ts
💤 Files with no reviewable changes (1)
  • src/services/pdf.ts
✅ Files skipped from review due to trivial changes (1)
  • src/lib/shortcuts.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/components/preview/PreviewApp.tsx
  • src/App.tsx
  • src/components/editor/Editor.tsx
  • src/App.css

📝 Walkthrough

Walkthrough

This PR adjusts print/PDF layout through comprehensive CSS changes with page margins and width constraints, implements a Cmd/Ctrl+Shift+P keyboard shortcut for printing with custom event handling, modifies Cmd/Ctrl+P behavior to require Shift not pressed, and adds semantic data attributes to editor layout elements for print targeting.

Changes

Cohort / File(s) Summary
Print Styling and Layout
src/App.css
Comprehensive print/PDF layout adjustments including global @page margins, width constraints for editor containers, semantic selector updates for sidebar/toolbar hiding, table formatting rules, and page-break control modifications.
Keyboard Shortcut Implementation
src/App.tsx, src/components/preview/PreviewApp.tsx, src/lib/shortcuts.ts
Added Cmd/Ctrl+Shift+P print shortcut with custom event dispatch, modified Cmd/Ctrl+P to require Shift not pressed, implemented cross-component event handling, and documented new shortcut in shortcut categories.
Editor Print Event Integration
src/components/editor/Editor.tsx
Registered custom print-note event listener triggering PDF download, added semantic data attributes to layout containers (data-format-bar, data-editor-content-area, data-editor-scroll), and removed descriptive comments.
PDF Service Cleanup
src/services/pdf.ts
Removed explanatory comments; core downloadPdf function behavior unchanged.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 A print shortcut hops into play,
Shift+P saves the day—
Custom events bound with care,
Semantic data attributes fair,
CSS margins align just right,
PDF exports in pristine sight! ✨📄

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: print as PDF renders blank page' is highly specific and directly addresses the core issue being fixed. It matches the main objective of the PR.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

- Add @page margin (0.75in) for proper PDF margins and override editor
  padding (pt-8/pb-24/px-6) in print CSS to prevent stacking
- Content exceeding printable area: add width constraints on containers,
  table-layout: fixed, and overflow-wrap: break-word
- Allow lists (ul/ol) to break across pages to avoid large whitespace gaps
- Hide format bar and toolbar via data attributes instead of fragile
  :has() selector that Tailwind v4 purges during build
- Add Cmd+P keyboard shortcut for print (standard shortcut), move
  command palette to Cmd+Shift+P
- Cmd+P and print menu work in both library notes and preview mode
  (files opened directly)
- Show toast before print dialog noting preview margin quirk (WebKit
  renders @page margins differently in preview vs actual output);
  dismiss toast immediately when dialog closes

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/App.css`:
- Around line 1123-1125: Replace deprecated usage of "word-break: break-word" by
removing it or setting "word-break: normal" and rely on the existing
"overflow-wrap: break-word" to achieve the desired behavior; update every
occurrence (e.g., the block containing "overflow-wrap: break-word !important;"
and the adjacent "word-break: break-word !important;" as well as the similar
blocks around the other reported locations) so Stylelint no longer flags the
deprecated value.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 11e6c057-a739-4527-af83-f5ac38ce9ad7

📥 Commits

Reviewing files that changed from the base of the PR and between 90af978 and ed0c22f.

📒 Files selected for processing (5)
  • src/App.css
  • src/App.tsx
  • src/components/editor/Editor.tsx
  • src/components/preview/PreviewApp.tsx
  • src/services/pdf.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/App.tsx
  • src/components/editor/Editor.tsx

Comment thread src/App.css
jordanlee and others added 2 commits March 28, 2026 23:48
…rence

Cmd+P now opens the command palette (more standard), Cmd+Shift+P triggers
print. Also blocks the browser print dialog in preview mode and adds the
print shortcut to the Settings > Shortcuts reference.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Resolve merge conflicts with shortcut centralization (lib/shortcuts.ts).
Remove print toast and 150ms delay, remove deprecated word-break: break-word.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Owner

@erictli erictli left a comment

Choose a reason for hiding this comment

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

@jordanlee - thanks for this fix (and for improving some of the existing code)! I resolved some conflicts with parallel PRs and removed the toast because I didn't feel it was necessary.

@erictli erictli merged commit 509f4a5 into erictli:main Apr 3, 2026
2 checks passed
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.

2 participants