-
Notifications
You must be signed in to change notification settings - Fork 488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: Interactive Editor doesn't honor theme after reload #5428
Comments
Thank you for reporting @hu0p! This is on my list to address today. |
@schalkneethling So using Anyway, thanks for the fix and nice work! |
So, initially it had the wrong event listener syntax. Someone did |
Is this considered fixed? I'm still experiencing inconsistent theme adherance. What is the problem?If the theme is toggled to light mode on a page without an interactive editor, subsequently navigating to a page with an interactive editor will display the editor in dark mode. Steps to reproduce the issue
EnvironmentDeviceDesktop BrowsersFirefox: 98.0.1 (64-bit) Operating systemMac OS: 12.2.1 |
Summary
If you visit any page with a Code Mirror REPL/Interactive Editor (brought to you by Bob) and toggle the theme to the opposite of your system's preferred color scheme the interactive editor's theme will update but this will not persist for subsequent visits.
Where did you spot the bug?
Any page with an interactive editor will do e.g. JavaScript's Map Reference.
What is the problem?
Bob uses
@media (prefers-color-scheme: ...) {...}
to match the system's configured color scheme by default. Bob also listens for postMessages from the client with a defined theme. When the state is updated on the client by the user toggling the theme switcher, Bob updates the theme accordingly and sets the theme in localstorage. There is a call to fetch it and apply it onreadystatechange.However, this doesn't seem to work. The key/value pair appears to never be set in localStorage for the relevant domain. This might be due in part because blocking third-party cookies appears to also mean blocking access to localStorage in frames to prevent user tracking, but the value is not set even if I temporarily allow all cookies. Additionally, the value is not respected even if I manually set it on the appropriate domain in DevTools (with all cookies temporarily allowed) but it does persist across visits.
This issue might be better suited for where Bob lives. If that's the case, let me know and I can cross-post it there. I just happened to start digging in and writing this up here first.
Anyway, one solution may be to always push the selected color scheme on hydration by calling
switchTheme
withdark
inside auseEffect
within theThemeToggle
component.Lastly, I guess it's "BoB", not "Bob" but the latter just sounded a lot more fun. Bob's a fun guy.
What did you expect to happen?
The embedded interactive editor's theme should match the site-wide, user selected theme on subsequent visits.
Steps to reproduce the issue
Environment
Device
Desktop
Browser
Chrome: 98.0.4758.109 (Official Build) (x86_64)
Operating system
Mac OS: 12.2.1
Screenshots
The text was updated successfully, but these errors were encountered: