Repository navigation
fix: White flash on language switch in dark mode #101 - #135
Conversation
|
@rue-eru is attempting to deploy a commit to the davidsupport's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughTheme class ownership is moved from imperative client-side effects to the server. ChangesCookie-based theme persistence
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 3❌ Failed checks (2 warnings, 1 inconclusive)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/app/[lang]/layout.tsx (1)
51-56:⚠️ Potential issue | 🔴 CriticalInline script will be blocked by CSP—nonce attribute is missing.
The CSP policy requires
script-src 'self' 'nonce-${nonce}'(no'unsafe-inline'), but the inline theme script at lines 51–56 lacks a nonce attribute. Thex-nonceheader is set inproxy.tsbut never read or applied in the layout. This will cause the script to be blocked on every request, reintroducing theme flicker on cold loads.Add nonce consumption to the layout: import
headers()from"next/server", readx-nonce, and apply it to the script element.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/app/`[lang]/layout.tsx around lines 51 - 56, The inline script element with dangerouslySetInnerHTML that applies the theme class is missing a nonce attribute required by your CSP policy. To fix this, import the headers function from "next/server" at the top of the layout file, then call headers() within the layout component to retrieve the x-nonce header value. Add the nonce attribute to the script element by setting nonce={nonce} where nonce is the value extracted from the headers. This ensures the inline theme script passes the CSP check and prevents the script from being blocked on every request.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@src/app/`[lang]/layout.tsx:
- Around line 51-56: The inline script element with dangerouslySetInnerHTML that
applies the theme class is missing a nonce attribute required by your CSP
policy. To fix this, import the headers function from "next/server" at the top
of the layout file, then call headers() within the layout component to retrieve
the x-nonce header value. Add the nonce attribute to the script element by
setting nonce={nonce} where nonce is the value extracted from the headers. This
ensures the inline theme script passes the CSP check and prevents the script
from being blocked on every request.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 66708f0e-a555-48ad-a024-142db1ac8837
📒 Files selected for processing (3)
src/app/[lang]/layout.tsxsrc/components/layout/ThemeToggle.tsxsrc/lib/use-theme.ts
i see, let me fix it then |
Overview
Changes
useEffectto server-side layoutDetails
darkclass on<html>was managed on the client viauseEffect<html>and resets itsclassNameuseEffectactivates after page rendering due to being on aclient-side, which caused thedarkclassto appear with a delay leading to a white screenTesting
I couldn't test locally due to build issues, but the logic follows the root cause analysis. Please review and test on your end.
Files changed
src/app/[lang]/layout.tsx: added cookie reading andclassNamefor themesrc/components/layout/ThemeToggle.tsx: added cookie sync on togglesrc/lib/use-theme.ts: removeduseEffectandpathnamedependencyCloses #101
Summary by CodeRabbit
New Features
Bug Fixes