-
Notifications
You must be signed in to change notification settings - Fork 98
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
Changes to system preference made when site is not open are not honoured #52
Comments
No, update ou workaround. I just don't use use-dark-mode where this is an issue. It updates when the page is open because it has an event listener that updates the saved state when it changes. However when the page isn't open that event listener isn't listening for the change. So the system value copied into local storage is never updated. |
I found a workaround that fixed it for me, using an
|
Great solution! I think that should be the default behavior ...
El mié., 2 de diciembre de 2020 7:38 a. m., Nils Buschhüter <
[email protected]> escribió:
… I found a workaround that fixed it for me, using an useEffect hook and
initializing useDarkMode without persistent storage.
const darkMode = useDarkMode(false, {
storageKey: null
});
useEffect(() => {
const darkThemeMq = window.matchMedia("(prefers-color-scheme: dark)");
if(darkThemeMq.matches) {
darkMode.enable();
} else {
darkMode.disable();
}
});
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#52 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AMV42QXWIBXPHU6GLLNK3VTSSYYN7ANCNFSM4NMWWFJA>
.
|
The useDarkMode hook can handle changes to system dark/light mode preference if the website is open during the preference change. However if the system's dark/light mode preference is changed when the user is not visiting the website it will remain in the previous state instead of updating. This happens even if the original preference came from the system setting and the user never interacted with a toggle suggesting a preference other than what their system declares.
How to test
Practical
This creates two problematic scenarios.
A user who visits a bunch of websites that use
use-dark-mode
, then months later decides they want a system wide dark mode and enables it, then visits a bunch of websites that useuse-dark-mode
. The new sites they visit will be in dark mode while the sites they visited months ago will be in light mode.Say a user uses f.lux's "Dark theme at sunset" setting, or iOS' "Light Until Sunset", or Android's "Dark theme: Schedule" setting. If they visit a website and it becomes sunset while they are visiting the site, it will switch to dark mode as the system switches. However if the user visits a website during the day, finishes, then next day visits the site at night the site will use the light theme even though it's night, the system is in dark mode, and the site would otherwise have been in dark mode.
The text was updated successfully, but these errors were encountered: