You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Added a theme switcher to the navbar so you can quickly toggle between light and dark mode.
Where it lives: The button is in the navbar on both desktop and mobile.
Component:
src/components/theme-toggle.tsx
Used in:
src/components/nav.tsx
No flicker on load: The app now sets your theme before the page fully loads to avoid a brief “flash” of the wrong theme.
Implemented in:
src/app/layout.tsx
Remembers your choice: Your theme preference is saved, so it stays the same when you come back.
PR Type
Enhancement
Description
Added theme toggle component for light/dark mode switching
Implemented FOUC prevention with inline script in layout
Integrated theme toggle in both desktop and mobile navigation
Added localStorage persistence for theme preferences
Diagram Walkthrough
flowchart LR
A["User clicks theme toggle"] --> B["ThemeToggle component"]
B --> C["Update DOM classes"]
B --> D["Save to localStorage"]
E["Page load"] --> F["Inline script"]
F --> G["Apply saved theme"]
G --> H["Prevent FOUC"]
Loading
File Walkthrough
Relevant files
Enhancement
theme-toggle.tsx
New theme toggle component implementation
src/components/theme-toggle.tsx
Created new theme toggle component with light/dark mode switching
Implemented localStorage persistence for theme preferences
Below is a summary of compliance checks for this PR:
Security Compliance
⚪
Inline script CSP risk
Description: The inline script uses dangerouslySetInnerHTML and accesses localStorage/window without feature-policy checks, which could be blocked in restrictive CSP or SSR contexts and may require a nonce/hash-based CSP to avoid XSS risks. layout.tsx [21-36]
Referred Code
<scriptdangerouslySetInnerHTML={{__html: ` (function() { try { var stored = localStorage.getItem('theme'); var prefersDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches; var theme = stored || (prefersDark ? 'dark' : 'light'); var root = document.documentElement; if (theme === 'dark') root.classList.add('dark'); else root.classList.remove('dark'); } catch (e) {} })(); `,}}/>
Ticket Compliance
⚪
🎫 No ticket provided
Create ticket/issue
Codebase Duplication Compliance
⚪
Codebase context is not defined
Follow the guide to enable codebase context checks.
Custom Compliance
⚪
No custom compliance provided
Follow the guide to enable custom compliance check.
Compliance status legend
🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label
Replace the custom theme-switching logic with the next-themes library. This simplifies the implementation by removing the manual inline script for FOUC prevention and direct DOM manipulation, resulting in more robust and maintainable code.
const[theme,setTheme]=useState<"light"|"dark">("light");useEffect(()=>{// Initialize from current DOM (set by inline script) or systemconstisDark=document.documentElement.classList.contains("dark");setTheme(isDark ? "dark" : "light");},[]);consttoggle=()=>{constnext=theme==="dark" ? "light" : "dark";
... (clipped10lines)
Why: The suggestion correctly identifies that the PR reinvents a common feature and proposes using a standard, robust library (next-themes) which would significantly simplify the code, improve maintainability, and is considered best practice.
High
Possible issue
Prevent UI flicker on load
To prevent a UI flicker on load, delay rendering the theme toggle button until the component has mounted and the correct theme is determined on the client.
const [theme, setTheme] = useState<"light" | "dark">("light");
+const [mounted, setMounted] = useState(false);
useEffect(() => {
+ setMounted(true);
// Initialize from current DOM (set by inline script) or system
const isDark = document.documentElement.classList.contains("dark");
setTheme(isDark ? "dark" : "light");
}, []);
+if (!mounted) {+ // a placeholder to avoid layout shift and hydration mismatch+ return <div className="h-[34px] w-[78px] rounded-md border border-border" />;+}+
Apply / Chat
Suggestion importance[1-10]: 7
__
Why: The suggestion correctly identifies a UI flicker issue due to a mismatch between server-rendered and client-hydrated state, and proposes a standard and effective solution to fix it.
Medium
Use functional state update for reliability
Use a functional state update for setTheme in the toggle function to prevent race conditions from rapid clicks and ensure reliable theme switching.
Why: The suggestion correctly identifies a potential race condition with rapid clicks and proposes using a functional state update, which is a best practice for robustness.
Low
More
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
User description
Added a theme switcher to the navbar so you can quickly toggle between light and dark mode.
Where it lives: The button is in the navbar on both desktop and mobile.
Component:
src/components/theme-toggle.tsx
Used in:
src/components/nav.tsx
No flicker on load: The app now sets your theme before the page fully loads to avoid a brief “flash” of the wrong theme.
Implemented in:
src/app/layout.tsx
Remembers your choice: Your theme preference is saved, so it stays the same when you come back.
PR Type
Enhancement
Description
Added theme toggle component for light/dark mode switching
Implemented FOUC prevention with inline script in layout
Integrated theme toggle in both desktop and mobile navigation
Added localStorage persistence for theme preferences
Diagram Walkthrough
File Walkthrough
theme-toggle.tsx
New theme toggle component implementationsrc/components/theme-toggle.tsx
nav.tsx
Integrated theme toggle in navigationsrc/components/nav.tsx
ThemeTogglecomponentlayout.tsx
FOUC prevention and theme initializationsrc/app/layout.tsx
suppressHydrationWarningto html element