File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1212 try {
1313 var t = localStorage . getItem ( "corbits-theme:last" ) ;
1414 var r = document . documentElement ;
15- if ( t === "dark" || t === "canvas" ) r . setAttribute ( "data-theme" , t ) ;
16- if ( t === "dark" ) r . classList . add ( "dark" ) ;
15+ if ( t !== "dark" && t !== "canvas" ) t = "light" ;
16+ r . setAttribute ( "data-theme" , t ) ;
17+ r . classList . add ( t === "dark" ? "dark" : "light" ) ;
1718 r . style . colorScheme = t === "dark" ? "dark" : "light" ;
1819 } catch ( e ) { }
1920 </ script >
Original file line number Diff line number Diff line change 11// The theme lives outside React: `data-theme` on <html> is the one switch,
2- // and this store is its only writer. Light is the absence of the attribute.
2+ // and this store is its only writer. Light is explicit too: react-ui's
3+ // `prefers-color-scheme: dark` block only skips roots carrying `.light`.
34
45import { reportError } from "@corbits/error-sink" ;
56import { useSyncExternalStore } from "react" ;
@@ -31,10 +32,10 @@ function readStored(key: string): Theme {
3132
3233function apply ( theme : Theme ) {
3334 const root = document . documentElement ;
34- if ( theme === "light" ) root . removeAttribute ( "data-theme" ) ;
35- else root . setAttribute ( "data-theme" , theme ) ;
36- // react-ui's `dark:` variant keys off the class.
35+ root . setAttribute ( "data-theme" , theme ) ;
36+ // react-ui's `dark:` variant keys off `.dark`; its OS-dark block excludes `.light`.
3737 root . classList . toggle ( "dark" , theme === "dark" ) ;
38+ root . classList . toggle ( "light" , theme !== "dark" ) ;
3839 root . style . colorScheme = theme === "dark" ? "dark" : "light" ;
3940}
4041
You can’t perform that action at this time.
0 commit comments