Skip to content

Fix print CSS partially applied due to external stylesheet timing - #60

Merged
patakuti merged 1 commit into
mainfrom
fix/print-css-timing
Jun 20, 2026
Merged

Fix print CSS partially applied due to external stylesheet timing#60
patakuti merged 1 commit into
mainfrom
fix/print-css-timing

Conversation

@patakuti

@patakuti patakuti commented Jun 20, 2026

Copy link
Copy Markdown
Owner

Closes #59

Summary

  • printPage() now waits for all <link rel="stylesheet"> elements to finish loading before calling window.print()
  • Cross-origin stylesheets (e.g. KaTeX CDN) that block .sheet access via CORS are skipped gracefully
  • A 3-second timeout ensures the print dialog is never blocked indefinitely if a stylesheet fails to load

Root Cause

On page load, switchTheme() is called with the theme from localStorage, which changes href on the theme <link> element and triggers a new HTTP request. Calling window.print() before this request completes results in a print preview without theme CSS applied.

Test plan

  • Open a markdown file, confirm a non-default theme is saved in localStorage
  • Click Print immediately after page load — verify theme CSS (colors, fonts) is correctly applied in print preview
  • Click Print after page is fully loaded — verify normal behavior unchanged

🤖 Generated with Claude Code

Wait for all <link rel="stylesheet"> elements to finish loading
before calling window.print(). This prevents the theme CSS
(dynamically switched via localStorage on page load) from being
missing in the print preview. A 3-second timeout ensures the
print dialog is never blocked indefinitely.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@patakuti
patakuti merged commit ba1ed09 into main Jun 20, 2026
1 check 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.

Print: CSS partially applied when theme is loaded via external stylesheet

1 participant