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 = () => {
8383 return ;
8484 }
8585
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+
8694 const script = document . createElement ( "script" ) ;
8795 script . src = "https://giscus.app/client.js" ;
8896 script . async = true ;
@@ -99,7 +107,7 @@ const GiscusComments: React.FC = () => {
99107 script . setAttribute ( "data-lang" , "en" ) ;
100108
101109 // Use the initial colorMode from Docusaurus for the initial theme
102- script . setAttribute ( "data-theme" , colorMode ) ;
110+ script . setAttribute ( "data-theme" , storedTheme ) ;
103111
104112 ref . current . appendChild ( script ) ;
105113 } , [ ] ) ; // <-- Empty dependency array ensures this runs only once on mount.
You can’t perform that action at this time.
0 commit comments