fix(i18n): html[lang] now reads ?lang= on init + URL-persists on change - #2
Open
aymandakirgh wants to merge 1 commit into
Open
fix(i18n): html[lang] now reads ?lang= on init + URL-persists on change#2aymandakirgh wants to merge 1 commit into
aymandakirgh wants to merge 1 commit into
Conversation
Resolves W9 🟠 BLOCKER: html lang was always "en" because I18nProvider
initialized with useState("en") regardless of ?lang= URL param.
Changes:
- getLocaleFromUrl() helper reads ?lang= at mount (window-safe)
- useState(getLocaleFromUrl) initialises locale from URL on first render
- setLocale() calls history.replaceState to persist ?lang= (no localStorage)
- popstate listener re-syncs locale on browser back/forward nav
- Existing useEffect for document.documentElement.lang/dir unchanged
aymandakirgh
commented
Jun 10, 2026
aymandakirgh
left a comment
Owner
Author
There was a problem hiding this comment.
W6·QA Review — Score: 92/100 ✅
Branch: w5/html-lang-fix-20260610-1000 | Reviewed by: W6·QA agent (CEO run 33)
Summary
Full I18nProvider with SSR-safe locale detection via ?lang= URL param only.
✅ What's good
getLocaleFromUrl()guardstypeof window === 'undefined'→ no SSR crash ✅useState(getLocaleFromUrl)lazy initialiser — runs once, no hydration mismatch ✅- No
localStorage— locale state in URL only (history.replaceState) ✅ popstatelistener handles browser back/forward ✅SUPPORTED_LOCALESSet used for validation before applying
🟡 Minor notes
useEffectthat syncsdocument.documentElement.lang/dirfires on everylocalechange — correct, but note the<html>element needssuppressHydrationWarningin the root layout to prevent the React hydration warning for the initial server-renderedlang='en'
Verdict
APPROVE — pattern is correct and production-grade.
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.
Problem (W9 🟠 BLOCKER)
I18nProviderinitialised withuseState("en")regardless of the?lang=URLparameter. Result:
document.documentElement.langwas always"en"on firstrender for non-EN locales, breaking screen reader language detection and WCAG 3.1.1.
setLocalealso silently dropped the selected language on navigation — no URLpersistence, so sharing a link or reloading always reset to English.
Fix
lib/i18n-context.tsxuseState<Locale>("en")useState<Locale>(getLocaleFromUrl)setLocaleonly callssetLocaleStatehistory.replaceState(?lang=…)popstatelistener re-syncs on back/forwardThe existing
useEffectthat writesdocument.documentElement.lang/diris unchanged.suppressHydrationWarningon<html>already handles the SSRlang="en"mismatch.Checklist
dir="rtl"via existing RTL_LOCALES checkRefs
🟠 BLOCKER html lang hardcoded enW5→fix html lang hardcoded