feat: Preserve locale with cookie & react-intl#58
feat: Preserve locale with cookie & react-intl#58canerakdas wants to merge 5 commits intonodejs:mainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR SummaryMedium Risk Overview Updates Reviewed by Cursor Bugbot for commit f168ee3. Bugbot is set up for automated code reviews on this repo. Configure here. |
There was a problem hiding this comment.
Pull request overview
Adds client-side locale detection (via NEXT_LOCALE) and uses it to localize navigation links from the Learn site back to locale-prefixed nodejs.org routes.
Changes:
- Introduces a
LocaleProvider(react-intlIntlProvider) that detects locale from theNEXT_LOCALEcookie. - Adds a link-localization utility and updates the navigation component to rewrite locale-prefixed links.
- Updates
site.jsonnavigation entries to include the default locale prefix and addsreact-intlas a dependency.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| util/link.js | New helper to rewrite locale-prefixed internal links. |
| providers/LocaleProvider.jsx | New provider to source locale from NEXT_LOCALE and expose it via react-intl. |
| components/Navigation/index.jsx | Uses detected locale to localize nav item links. |
| components/Layout/index.jsx | Wraps page layout with LocaleProvider. |
| site.json | Adds defaultLocale and updates nav links to include /en/ prefixes. |
| package.json | Adds react-intl dependency. |
| package-lock.json | Locks new react-intl and related FormatJS dependencies. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit f168ee3. Configure here.
| const value = { | ||
| locale: detectedLocale, | ||
| localizeLink: link => localizeLink(link, detectedLocale), | ||
| }; |
There was a problem hiding this comment.
Unmemoized context value defeats downstream useMemo
Medium Severity
The value object passed to LocaleContext.Provider is recreated on every render without useMemo, producing a new localizeLink function reference each time. This causes all context consumers to re-render on every parent render and completely defeats the useMemo in the Navigation component, which lists localizeLink as its sole dependency. The memoization in Navigation is effectively a no-op. The value needs to be wrapped in useMemo with [detectedLocale] as the dependency.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit f168ee3. Configure here.


This PR aims to preserve the current language across navigation between nodejs.org and learn pages if the
NEXT_LOCALEcookie is present.