rusackas commented on code in PR #42602:
URL: https://github.com/apache/superset/pull/42602#discussion_r3680999588


##########
docs/src/components/StorybookWrapper.jsx:
##########
@@ -78,15 +80,32 @@ function getProviders() {
       return container || document.body;
     };
 
+    // `themeObject` is a module-level singleton (superset-core/src/theme
+    // index.tsx: `Theme.fromConfig()`), created once with no dark/light
+    // config, so SupersetThemeProvider always rendered whatever that default
+    // algorithm was -- it had no way to know about Docusaurus's theme toggle.
+    // Docusaurus tracks the toggle in React context (useColorMode), so
+    // mirror it onto the singleton via the toggleDarkMode() method Theme
+    // already exposes for exactly this purpose.
+    function ThemeSync({ children }) {
+      const { colorMode } = useColorMode();
+      React.useEffect(() => {
+        themeObject.toggleDarkMode(colorMode === 'dark');
+      }, [colorMode]);

Review Comment:
   Good catch, fixed. Switched to `useLayoutEffect` so the sync runs before 
paint instead of after. This only ever mounts client-side (inside 
`BrowserOnly`), so no SSR mismatch to worry about there.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to