[SENTRY NK] Avoid eager CSSStyleSheet construction in PDF viewer#42
Merged
Merged
Conversation
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
self-requested a review
July 24, 2026 15:36
julliancalkins
approved these changes
Jul 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes C12-NK:
TypeError: Illegal constructoron Safari 16.1 whenrm-pdf-vieweris instantiated.createThemeStyleSheetcallednew CSSStyleSheet()directly, and_updateThemeColorsassignedshadowRoot.adoptedStyleSheets. Both APIs only shipped in Safari 16.4, so on older Safari the element constructor throws — in C12 this happened during Turbo'sdocument.importNodewhile opening a PDF attachment, breaking the modal entirely.Fix
theme-config.jsnow returns a lazy LitCSSResult(via thecsstag) instead of constructing aCSSStyleSheet; renamed tocreateThemeStylesto match._updateThemeColorsapplies styles with Lit'sadoptStyles, which usesadoptedStyleSheetswhere supported and falls back to appending<style>tags where not.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
theme-config.test.jsfor theCSSResultreturn type.globalThis.CSSStyleSheetwith a throwing constructor (the Safari < 16.4 condition) and assertscreateThemeStylesdoesn't throw.yarn buildoutput verified free of directnew CSSStyleSheet()calls.Fixes C12-NK
🤖 Generated with Claude Code
https://claude.ai/code/session_019rfbyCarrFPKUsY5mdq3rJ