From cedd79d7c4fa932fe834d737cbca2164ac9d57f8 Mon Sep 17 00:00:00 2001 From: santhosh-005 Date: Thu, 9 Oct 2025 11:12:49 +0530 Subject: [PATCH] fix(giscus): initialize giscus script with correct theme --- src/components/giscus.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/components/giscus.tsx b/src/components/giscus.tsx index f26d0ca8..8fd939be 100644 --- a/src/components/giscus.tsx +++ b/src/components/giscus.tsx @@ -83,6 +83,14 @@ const GiscusComments: React.FC = () => { return; } + // Use localStorage to get user's last theme or fallback to 'light' + const storedTheme = + localStorage.getItem("theme") || ( + document.documentElement.getAttribute("data-theme") === "dark" + ? "dark" + : "light" + ); + const script = document.createElement("script"); script.src = "https://giscus.app/client.js"; script.async = true; @@ -99,7 +107,7 @@ const GiscusComments: React.FC = () => { script.setAttribute("data-lang", "en"); // Use the initial colorMode from Docusaurus for the initial theme - script.setAttribute("data-theme", colorMode); + script.setAttribute("data-theme", storedTheme); ref.current.appendChild(script); }, []); // <-- Empty dependency array ensures this runs only once on mount.