File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -83,6 +83,14 @@ const GiscusComments: React.FC = () => {
83
83
return ;
84
84
}
85
85
86
+ // Use localStorage to get user's last theme or fallback to 'light'
87
+ const storedTheme =
88
+ localStorage . getItem ( "theme" ) || (
89
+ document . documentElement . getAttribute ( "data-theme" ) === "dark"
90
+ ? "dark"
91
+ : "light"
92
+ ) ;
93
+
86
94
const script = document . createElement ( "script" ) ;
87
95
script . src = "https://giscus.app/client.js" ;
88
96
script . async = true ;
@@ -99,7 +107,7 @@ const GiscusComments: React.FC = () => {
99
107
script . setAttribute ( "data-lang" , "en" ) ;
100
108
101
109
// Use the initial colorMode from Docusaurus for the initial theme
102
- script . setAttribute ( "data-theme" , colorMode ) ;
110
+ script . setAttribute ( "data-theme" , storedTheme ) ;
103
111
104
112
ref . current . appendChild ( script ) ;
105
113
} , [ ] ) ; // <-- Empty dependency array ensures this runs only once on mount.
You can’t perform that action at this time.
0 commit comments