-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add useLocale hook #2787
Add useLocale hook #2787
Conversation
🦋 Changeset detectedLatest commit: bf13f72 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Size Change: +412 B (+0.06%) Total Size: 642 kB
ℹ️ View Unchanged
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2787 +/- ##
==========================================
+ Coverage 87.29% 87.32% +0.03%
==========================================
Files 215 216 +1
Lines 12644 12675 +31
Branches 1694 1705 +11
==========================================
+ Hits 11037 11068 +31
Misses 1554 1554
Partials 53 53
|
Purpose
While investigating #2786, I realized that the current usage of the browser locale can lead to hydration errors. During server side rendering, the
getBrowserLocale
function returns the default locale (en-US
). During hydration on the client,getBrowserLocale
returns the user's preferred locale, causing the hydration mismatch.Approach and changes
useLocale
hook that returns the default locale during server side rendering and the initial client hydration, and updates it on the next render, thus avoiding the mismatch. Additionally, it listens to thelanguagechange
event. If a custom locale is passed, it is given priority.Definition of done