| ... | @@ -473,6 +473,10 @@ export function useTheme() { | ... | @@ -473,6 +473,10 @@ export function useTheme() { |
| 473 | const setTheme = useCallback((next: Theme): boolean => { | 473 | const setTheme = useCallback((next: Theme): boolean => { |
| 474 | if (typeof window === "undefined") return false; | 474 | if (typeof window === "undefined") return false; |
| 475 | try { | 475 | try { |
| | 476 | // Preserve the current mode before replacing a legacy or inferred theme |
| | 477 | // preference. Otherwise a fresh System preference is re-inferred from |
| | 478 | // the new theme's base appearance, which can switch a dark UI to light. |
| | 479 | writeAppearanceModePreference(readAppearanceModePreference(getStored())); |
| 476 | // Choosing a whole theme replaces any automatic-mode mix. The mix is | 480 | // Choosing a whole theme replaces any automatic-mode mix. The mix is |
| 477 | // captured first so a failed preference write can put it back instead | 481 | // captured first so a failed preference write can put it back instead |
| 478 | // of erasing it or leaving it attached to the new theme. | 482 | // of erasing it or leaving it attached to the new theme. |