Fix Firefox dark mode white background on comment iframe#2023
Fix Firefox dark mode white background on comment iframe#2023amdevz wants to merge 2 commits intoumputun:masterfrom
Conversation
Firefox renders a white background in dark mode when color-scheme is 'none' on the iframe. Set color-scheme to match the active theme on both the outer iframe element and the inner document root, so Firefox uses the correct rendering mode from the start and on theme changes.
a5b0310 to
3a20bbe
Compare
|
Thanks for the fix, the problem is real - Firefox does handle the invalid Some context on the history here:
One concern with the fallback in colorScheme: params.theme === 'dark' ? 'dark' : params.theme === 'light' ? 'light' : 'light dark'When theme is not set (undefined), this falls through to The fallback should be |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2023 +/- ##
==========================================
- Coverage 62.03% 61.89% -0.15%
==========================================
Files 132 132
Lines 3037 3044 +7
Branches 788 790 +2
==========================================
Hits 1884 1884
- Misses 1039 1156 +117
+ Partials 114 4 -110 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Changes the fallback from 'light dark' to 'light' to match the inner document's default behavior, which always defaults to light when no theme is specified.
Of course, thanks for taking a look. That's a valid concern, I think for this PR defaulting to |
Summary
color-scheme: noneis not a valid CSS value. Chrome silently ignores it, but Firefox treats it literally and uses the default light canvas.color-schemeon the iframe's inner<html>element to match the active theme (darkorlight), which tells Firefox to use the correct canvas color.<iframe>element'scolor-schemeon creation and on runtime theme changes viachangeTheme().Changes
remark.tsx: Setsdocument.documentElement.style.colorSchemeinside the iframe on init and when receiving theme change messagesembed.ts: Updatesiframe.style.colorSchemewhenchangeTheme()is called at runtimecreate-iframe.ts: Replaces invalidcolorScheme: 'none'with a theme-aware value ('dark','light', or'light dark')Test plan
http://127.0.0.1:8080/web/in Firefox and ChromechangeTheme('dark')andchangeTheme('light')in the console both update the iframe canvas colorBefore
Firefox
Dark
Chromium
Dark
After
Firefox
Light
Dark
Chromium
Light
Dark