Skip to content

Commit 450422a

Browse files
fixed bugs
1 parent 079c41e commit 450422a

File tree

6 files changed

+33
-103
lines changed

6 files changed

+33
-103
lines changed
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import React, { useEffect } from "react";
2-
import ReactDOM from "react-dom/client";
1+
import React, { useEffect, useState } from "react";
2+
import { createPortal } from "react-dom";
33
import FirebaseAuthGithub from "./FirebaseAuthGithub";
44

55
const NavbarFirebaseAuthGithub: React.FC = () => {
6+
const [container, setContainer] = useState<HTMLElement | null>(null);
7+
68
useEffect(() => {
7-
const container = document.getElementById("firebase-auth-github-navbar");
8-
if (container && !container.hasChildNodes()) {
9-
const root = ReactDOM.createRoot(container);
10-
root.render(<FirebaseAuthGithub />);
11-
}
9+
const el = document.getElementById("firebase-auth-github-navbar");
10+
setContainer(el);
1211
}, []);
13-
return null;
12+
13+
return container ? createPortal(<FirebaseAuthGithub />, container) : null;
1414
};
1515

1616
export default NavbarFirebaseAuthGithub;

src/pages/badges/github-badges.tsx

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,6 @@ import Head from '@docusaurus/Head';
33
import { motion, HTMLMotionProps } from 'framer-motion';
44
import type { ReactElement } from 'react';
55
import Layout from '@theme/Layout';
6-
import { useColorMode } from '@docusaurus/theme-common';
7-
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
8-
9-
// Safe hook for color mode that handles SSR
10-
function useSafeColorMode() {
11-
const [mounted, setMounted] = useState(false);
12-
13-
useEffect(() => {
14-
setMounted(true);
15-
}, []);
16-
17-
let colorMode = 'light';
18-
let isDark = false;
19-
20-
if (mounted && ExecutionEnvironment.canUseDOM) {
21-
try {
22-
const { useColorMode: useColorModeHook } = require('@docusaurus/theme-common');
23-
const colorModeResult = useColorModeHook();
24-
colorMode = colorModeResult.colorMode;
25-
isDark = colorMode === 'dark';
26-
} catch (error) {
27-
console.warn('Failed to get color mode:', error);
28-
}
29-
}
30-
31-
return { colorMode, isDark, mounted };
32-
}
336
import styles from './github-badges.module.css';
347

358
type MotionDivProps = HTMLMotionProps<"div">;
@@ -38,7 +11,13 @@ type MotionTrProps = HTMLMotionProps<"tr">;
3811
import Link from '@docusaurus/Link';
3912

4013
const GithubBadgesContent = (): React.ReactElement => {
41-
const { colorMode, isDark, mounted } = useSafeColorMode();
14+
const [isDark, setIsDark] = useState(false);
15+
useEffect(() => {
16+
try {
17+
const theme = document.documentElement.getAttribute('data-theme');
18+
setIsDark(theme === 'dark');
19+
} catch {}
20+
}, []);
4221

4322
// Scroll to top button logic
4423
useEffect(() => {

src/pages/careers/index.tsx

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,6 @@ import Layout from "@theme/Layout";
33
import Head from "@docusaurus/Head";
44
import { motion } from "framer-motion";
55
import Link from "@docusaurus/Link";
6-
import { useColorMode } from '@docusaurus/theme-common';
7-
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
8-
9-
// Safe hook for color mode that handles SSR
10-
function useSafeColorMode() {
11-
const [mounted, setMounted] = useState(false);
12-
13-
useEffect(() => {
14-
setMounted(true);
15-
}, []);
16-
17-
let colorMode = 'light';
18-
let isDark = false;
19-
20-
if (mounted && ExecutionEnvironment.canUseDOM) {
21-
try {
22-
const { useColorMode: useColorModeHook } = require('@docusaurus/theme-common');
23-
const colorModeResult = useColorModeHook();
24-
colorMode = colorModeResult.colorMode;
25-
isDark = colorMode === 'dark';
26-
} catch (error) {
27-
console.warn('Failed to get color mode:', error);
28-
}
29-
}
30-
31-
return { colorMode, isDark, mounted };
32-
}
336

347
// Animation variants for consistent animations
358
const fadeIn = {
@@ -151,7 +124,13 @@ const testimonials = [
151124
];
152125

153126
function CareersContent() {
154-
const { colorMode, isDark, mounted } = useSafeColorMode();
127+
const [isDark, setIsDark] = useState(false);
128+
useEffect(() => {
129+
try {
130+
const theme = document.documentElement.getAttribute('data-theme');
131+
setIsDark(theme === 'dark');
132+
} catch {}
133+
}, []);
155134
const [activeTestimonial, setActiveTestimonial] = useState(0);
156135

157136
useEffect(() => {

src/pages/get-started/index.tsx

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,6 @@ import Link from "@docusaurus/Link";
44
import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
55
import { motion, useAnimation, useInView } from "framer-motion";
66
import Head from '@docusaurus/Head';
7-
import { useColorMode } from '@docusaurus/theme-common';
8-
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
9-
10-
// Safe hook for color mode that handles SSR
11-
function useSafeColorMode() {
12-
const [mounted, setMounted] = useState(false);
13-
14-
useEffect(() => {
15-
setMounted(true);
16-
}, []);
17-
18-
let colorMode = 'light';
19-
let isDark = false;
20-
21-
if (mounted && ExecutionEnvironment.canUseDOM) {
22-
try {
23-
const { useColorMode: useColorModeHook } = require('@docusaurus/theme-common');
24-
const colorModeResult = useColorModeHook();
25-
colorMode = colorModeResult.colorMode;
26-
isDark = colorMode === 'dark';
27-
} catch (error) {
28-
console.warn('Failed to get color mode:', error);
29-
}
30-
}
31-
32-
return { colorMode, isDark, mounted };
33-
}
347
import styles from "./styles.module.css";
358

369
// Type definitions
@@ -635,7 +608,13 @@ const LearningPath = ({
635608

636609
function GetStartedContent() {
637610
const { siteConfig } = useDocusaurusContext();
638-
const { colorMode, isDark, mounted } = useSafeColorMode();
611+
const [isDark, setIsDark] = useState(false);
612+
useEffect(() => {
613+
try {
614+
const theme = document.documentElement.getAttribute('data-theme');
615+
setIsDark(theme === 'dark');
616+
} catch {}
617+
}, []);
639618
type CompletedPaths = Record<string, boolean>;
640619

641620
const [completedPaths, setCompletedPaths] = useState<CompletedPaths>(() => {

src/theme/Layout.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React from "react";
22
import Layout from "@theme-original/Layout";
3-
import NavbarFirebaseAuthGithub from "@site/src/components/ui/NavbarFirebaseAuthGithub";
43
import NewsletterPopup from '../components/NewsLetterPopup';
54

65

@@ -10,7 +9,6 @@ export default function CustomLayout({ children, ...props }) {
109
return (
1110
<>
1211
<Layout {...props}>
13-
<NavbarFirebaseAuthGithub />
1412
{children}
1513
</Layout>
1614
<NewsletterPopup />

src/theme/Root.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
import React from 'react';
2-
import { Analytics } from '@vercel/analytics/react';
2+
import OriginalRoot from '@theme-original/Root';
33

4-
// Default implementation, that you can customize
5-
export default function Root({children}) {
6-
return (
7-
<>
8-
{children}
9-
<Analytics />
10-
</>
11-
);
4+
// Delegate entirely to the original Root to preserve all providers during SSG
5+
export default function Root(props) {
6+
return <OriginalRoot {...props} />;
127
}

0 commit comments

Comments
 (0)