Skip to content

Commit

Permalink
Fix dark signal for docusaurus (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
pearmini committed Aug 1, 2024
1 parent 92ad6a1 commit 89da07f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/genji-theme-docusaurus/src/theme/DocRoot/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useLocation } from "@docusaurus/router";

function useDark() {
const [dark, setDark] = React.useState(false);

useEffect(() => {
const observer = new MutationObserver((mutationsList) => {
for (const mutation of mutationsList) {
Expand All @@ -14,8 +15,10 @@ function useDark() {
}
});
observer.observe(document.documentElement, { attributes: true });

return () => observer.disconnect();
}, []);

return dark;
}

Expand All @@ -26,9 +29,12 @@ export default function DocRoot(props) {

useEffect(() => {
const config = window.__genjiConfig || {};
if (!pageRef.current) pageRef.current = new Page(config);
if (!pageRef.current) pageRef.current = new Page({ isDark: dark, ...config });
pageRef.current.render();
return () => pageRef.current.dispose();
return () => {
pageRef.current.dispose();
pageRef.current = null;
};
}, [location.pathname]);

useEffect(() => {
Expand Down

0 comments on commit 89da07f

Please sign in to comment.