Skip to content

feat: add complete dark mode (ThemeContext, CSS variables, FOWT prevention, Header toggle)#5

Open
m-mohamed wants to merge 3 commits intoxizon:mainfrom
m-mohamed:corvus/pm-session-1773451873628
Open

feat: add complete dark mode (ThemeContext, CSS variables, FOWT prevention, Header toggle)#5
m-mohamed wants to merge 3 commits intoxizon:mainfrom
m-mohamed:corvus/pm-session-1773451873628

Conversation

@m-mohamed
Copy link

@m-mohamed m-mohamed commented Mar 14, 2026

Summary

  • CSS Custom Properties: Extracted all hardcoded colors from globals.scss into --color-* CSS variables on :root; added [data-theme='dark'] override block with dark-mode equivalents
  • ThemeContext: New src/contexts/ThemeContext.tsx following the JWTAuthContext pattern — useReducer state, useLocalStorage persistence, prefers-color-scheme fallback, document.documentElement.setAttribute('data-theme', ...) in useEffect
  • Provider registration: ThemeProvider added to ProviderLayout.tsx wrapping AuthProvider
  • FOWT prevention: suppressHydrationWarning={true} on <html> element; beforeInteractive Script in layout.tsx reads localStorage and sets data-theme before React hydrates
  • SCSS modules updated: Replaced hardcoded colors in Buttons, Modal, MultilevelDropdownMenu, and Pagination with var(--color-*) references
  • Header toggle: Sun/moon toggle button in src/components/Header/index.tsx using useTheme hook

Test plan

  • Toggle theme in Header — theme switches immediately (light ↔ dark)
  • Reload page — same theme is restored from localStorage
  • Open a new tab cold — no visible flash of wrong theme (FOWT)
  • ./node_modules/.bin/eslint src/contexts/ThemeContext.tsx src/components/Header/index.tsx app/layout.tsx app/ProviderLayout.tsx — passes with no errors
  • npx tsc --noEmit — no new type errors (two pre-existing errors in @pages/index.tsx and app/ClientPage.tsx are unrelated)
  • npm run dev — server starts cleanly on port 3000

🤖 Generated with Claude Code

…ggle

- Define CSS custom properties (--color-*) on :root and [data-theme='dark']
  in globals.scss for all themed colors
- Create ThemeContext.tsx following JWTAuthContext pattern: useReducer state,
  useLocalStorage persistence, prefers-color-scheme fallback, and
  document.documentElement.setAttribute effect
- Register ThemeProvider in ProviderLayout.tsx wrapping AuthProvider
- Add suppressHydrationWarning to <html> in layout.tsx; add beforeInteractive
  Script that reads localStorage and sets data-theme before React hydrates
  (FOWT prevention)
- Replace hardcoded colors in Buttons, Modal, MultilevelDropdownMenu, and
  Pagination SCSS modules with var(--color-*) references
- Add sun/moon toggle button in Header using useTheme hook
@vercel
Copy link

vercel bot commented Mar 14, 2026

Someone is attempting to deploy a commit to the xizon's projects Team on Vercel.

A member of the Team first needs to authorize it.

Corvus Harness and others added 2 commits March 14, 2026 01:47
- Replace hardcoded http://localhost:3000 URLs in localConfig with
  relative paths to fix CORS when accessed via 127.0.0.1
- Replace removed `next lint` command with direct eslint invocation
- Add missing typecheck (tsc --noEmit) and test scripts to package.json

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… calls

demoMenuActions.js is called server-side from app/page.tsx during SSR.
The previous CORS fix changed localConfig.MENU to a relative URL (/api/navigation),
but axios in Node.js cannot resolve relative URLs, causing Invalid URL errors
and a 500 on the home page.

Detect server-side context (typeof window === 'undefined') and prefix relative
URLs with the absolute localhost base URL so axios can resolve them. Client-side
browser calls continue using relative URLs (no CORS issue).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@m-mohamed m-mohamed closed this Mar 14, 2026
@vercel
Copy link

vercel bot commented Mar 15, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
fullstack-nextjs-app-template Ready Ready Preview, Comment Mar 15, 2026 11:53am

@xizon
Copy link
Owner

xizon commented Mar 15, 2026

There is a small issue that after refreshing the page, localStorage reverts to empty, causing the theme to become invalid. :)

@xizon xizon reopened this Mar 15, 2026
@xizon
Copy link
Owner

xizon commented Mar 15, 2026

you could fix this, it may be caused by the initialized script I guess. thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants