Fix Firefox dark mode white background on comment iframe#2023
Fix Firefox dark mode white background on comment iframe#2023umputun merged 2 commits intoumputun:masterfrom
Conversation
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.28% 62.14% -0.15%
==========================================
Files 133 133
Lines 3031 3038 +7
Branches 741 743 +2
==========================================
Hits 1888 1888
- Misses 1139 1146 +7
Partials 4 4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Of course, thanks for taking a look. That's a valid concern, I think for this PR defaulting to |
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.
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.
54231b0 to
464e814
Compare
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