Skip to content

[SENTRY NK] Avoid eager CSSStyleSheet construction in PDF viewer#42

Merged
jdmcleod merged 1 commit into
mainfrom
sentry-nk-avoid-eager-cssstylesheet-construction
Jul 24, 2026
Merged

[SENTRY NK] Avoid eager CSSStyleSheet construction in PDF viewer#42
jdmcleod merged 1 commit into
mainfrom
sentry-nk-avoid-eager-cssstylesheet-construction

Conversation

@jdmcleod

Copy link
Copy Markdown
Collaborator

Summary

Fixes C12-NK: TypeError: Illegal constructor on Safari 16.1 when rm-pdf-viewer is instantiated.

createThemeStyleSheet called new CSSStyleSheet() directly, and _updateThemeColors assigned shadowRoot.adoptedStyleSheets. Both APIs only shipped in Safari 16.4, so on older Safari the element constructor throws — in C12 this happened during Turbo's document.importNode while opening a PDF attachment, breaking the modal entirely.

Fix

  • theme-config.js now returns a lazy Lit CSSResult (via the css tag) instead of constructing a CSSStyleSheet; renamed to createThemeStyles to match.
  • _updateThemeColors applies styles with Lit's adoptStyles, which uses adoptedStyleSheets where supported and falls back to appending <style> tags where not.
  • Bumped version to 0.0.10.

Behavior on modern browsers is unchanged (same adopted-stylesheets path as before). On Safari < 16.4 the viewer now renders instead of crashing — note theme colors there still degrade gracefully since the CSS uses light-dark() (Safari 17.5+).

Tests

  • Updated theme-config.test.js for the CSSResult return type.
  • Added a regression test that replaces globalThis.CSSStyleSheet with a throwing constructor (the Safari < 16.4 condition) and asserts createThemeStyles doesn't throw.
  • Full suite: 53 passed. yarn build output verified free of direct new CSSStyleSheet() calls.

Fixes C12-NK

🤖 Generated with Claude Code

https://claude.ai/code/session_019rfbyCarrFPKUsY5mdq3rJ

Fixes C12-NK

Sentry: https://rolemodel-software.sentry.io/issues/C12-NK

createThemeStyleSheet called new CSSStyleSheet() directly, which throws
TypeError: Illegal constructor on browsers without constructable
stylesheet support (Safari < 16.4) — crashing the rm-pdf-viewer element
constructor. Return a lazy Lit CSSResult instead and apply it with
Lit's adoptStyles, which falls back to <style> tags when adopted
stylesheets are unsupported.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019rfbyCarrFPKUsY5mdq3rJ
@julliancalkins
julliancalkins self-requested a review July 24, 2026 15:36
@jdmcleod
jdmcleod merged commit b879c13 into main Jul 24, 2026
1 check passed
@jdmcleod
jdmcleod deleted the sentry-nk-avoid-eager-cssstylesheet-construction branch July 24, 2026 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants