feat(theme): ThemeProvider + useTheme foundation (closes #1030)#1122
Open
jeromehardaway wants to merge 1 commit into
Open
feat(theme): ThemeProvider + useTheme foundation (closes #1030)#1122jeromehardaway wants to merge 1 commit into
jeromehardaway wants to merge 1 commit into
Conversation
Closes #1030. src/contexts/theme-context.tsx exports ThemeProvider, useTheme, and a pre-paint script. The provider holds the user's preference (light/dark/system), reads it from localStorage on mount, subscribes to (prefers-color-scheme: dark) when in system mode, and toggles the dark class on <html> via Tailwind's class-based dark mode. THEME_PREPAINT_SCRIPT is a dependency-free IIFE injected into _document.tsx so the dark class is on <html> before first paint. Without it, dark-mode users see a flash of light content on load. Tests cover system resolution, stored preference, persistence, live OS sync, system-to-explicit transition, and useTheme outside provider throwing — 6 cases. Does not wire the provider into _app.tsx yet (that's #1031).
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
Pull request overview
Adds the foundation for dark-mode theme state management and pre-paint theme application, supporting the upcoming provider integration and toggle UI work.
Changes:
- Added
ThemeProvider,useTheme, theme persistence, system preference syncing, and pre-paint script export. - Injected the pre-paint script into
_document.tsx. - Added tests for theme defaults, persistence, OS syncing, and provider enforcement.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/contexts/theme-context.tsx |
Defines theme context, provider logic, hook, and inline pre-paint script. |
src/pages/_document.tsx |
Injects the pre-paint script into the document head. |
__tests__/contexts/theme-context.test.tsx |
Adds coverage for theme provider and hook behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+71
to
+73
| useEffect(() => { | ||
| const stored = readStoredTheme(); | ||
| setThemeState(stored); |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
First piece of the dark-mode track. Adds theme state management and the pre-paint script that prevents FOUC. Does not wire the provider into `_app.tsx` yet (that's #1031) or render any UI — strictly the foundation.
`src/contexts/theme-context.tsx`
`src/pages/_document.tsx`
Tests
`tests/contexts/theme-context.test.tsx` — 6 cases (6/6 pass):
Closes #1030. Unblocks #1031, #1032, #1033, #1034.
Test plan