Commit feb4a41
authored
fix: correct default dark-mode preference (#1069)
Thanks for shipping Dark mode for JSR! (#1055) 🎉
Though I noticed that the media `prefers-color-scheme` detection is not
working correctly. During loading the correct theme will be applied (via
`_app.tsx` script), but when Preact renders it will override with
incorrect theme. This is because the `isDarkStored ?? isDarkPreference`
expression basically always returning `isDarkStored` (`isDarkStored` is
`boolean`, not `boolean | undefined | null`).
This PR attempts to fix the issue by ensuring the [logic is the same as
for
`_app.tsx`](https://github.com/jsr-io/jsr/blob/main/frontend/routes/_app.tsx#L74-L81)
for when Dark mode should be applied, which avoids dark -> light
flashing for when dark mode is preferred without any stored value.
## Current behavior
This is how it looks for me (3G throttled) when I have no `darkMode`
localeStorage item.
https://github.com/user-attachments/assets/56ff105f-5a39-46ff-bf6c-40f518366ed21 parent 2c71e6b commit feb4a41
1 file changed
+3
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
0 commit comments