fix(frontend): document SSR/hydration guard in theme provider (#1083) - #1169
Merged
Merged
Conversation
omoh5
force-pushed
the
fix/1083-theme-ssr-hydration-docs
branch
from
August 4, 2026 22:06
1c4e2bf to
1d56622
Compare
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.
Description
Closes #1083
This PR resolves the open SSR/hydration concern for the theme provider by documenting the existing guard strategy in code comments rather than adding a redundant hand-rolled inline script.
Context: A previous attempt (PR #1158) added a custom blocking inline
<script>tolayout.tsx. A maintainer closed it with the guidance thatmainalready ships both halves of the protection:suppressHydrationWarningon<html>infrontend/src/app/layout.tsx— tells React to skip the hydration diff check for the class attribute, since the pre-paint script intentionally mutates it.next-themes@0.4.6's built-in blocking pre-paint script (the library's core feature) — it readslocalStorage["flowfi-theme"], resolves"system"viamatchMedia("(prefers-color-scheme: dark)"), and adds/removes thedarkclass ondocument.documentElementbefore the first paint.A second hand-rolled script would race the built-in one, so this PR deliberately does not add one. Instead it documents the strategy so the intent is preserved for future contributors (acceptance criterion: "Document the approach in a code comment").
Type of Change
Related Issues
Closes #1083
Changes Made
frontend/src/context/theme-provider.tsx— Added a JSDoc block documenting the full SSR/hydration strategy:next-themes' built-in pre-paint script prevents flash-of-wrong-theme (FOUC).suppressHydrationWarningon<html>prevents the hydration mismatch warning.ThemeProviderprop does (attribute,defaultTheme,enableSystem,storageKey,disableTransitionOnChange).frontend/src/app/layout.tsx— Replaced the staleTODOcomment with an explanation of whysuppressHydrationWarningis on<html>and how it pairs with the next-themes pre-paint script rendered by<ThemeProvider>.No functional change — the current behavior already satisfies acceptance criteria 1–2 (see Testing for evidence).
Testing
npm run lint --workspace=frontend— 0 errors (5 pre-existing warnings in unrelated files)npm run build --workspace=frontend(Next.js 16.2.9, Turbopack) — succeedsnpm test --workspace=frontend— 206 tests passed (24 files).next/server/app/index.html) to confirm current behavior:suppressHydrationWarning:trueis serialized on the<html>element in the React tree (honored at hydration)....("class","flowfi-theme","dark",null,["light","dark",...])— the library's inline script readslocalStorage["flowfi-theme"](default"dark") and applies the class before paint.attribute="class",defaultTheme="dark",enableSystem=true,storageKey="flowfi-theme",disableTransitionOnChange).Test Coverage
Test Steps
Manual repro for reviewers:
cd frontend && npm run devlocalStorage.setItem('flowfi-theme', 'light')and hard-reload — there is no dark→light flash on load (theme is correct before first paint).Hydration mismatchwarnings.Breaking Changes
None — comment-only change.
Migration Guide: N/A
Checklist
Additional Notes
next-themes' built-in script; this PR follows that guidance).pre-commithook (lint-staged →npm run lint --workspace=frontend) passed on commit.