Skip to content

feat: Preserve locale with cookie & react-intl#58

Open
canerakdas wants to merge 5 commits intonodejs:mainfrom
canerakdas:feat/preserve-locale-with-cookie
Open

feat: Preserve locale with cookie & react-intl#58
canerakdas wants to merge 5 commits intonodejs:mainfrom
canerakdas:feat/preserve-locale-with-cookie

Conversation

@canerakdas
Copy link
Copy Markdown
Member

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

Copilot AI review requested due to automatic review settings April 23, 2026 17:36
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 23, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
nodejs-learn Ready Ready Preview Apr 26, 2026 11:04am

Request Review

@cursor
Copy link
Copy Markdown

cursor Bot commented Apr 23, 2026

PR Summary

Medium Risk
Updates global layout/nav to rewrite navigation links based on the NEXT_LOCALE cookie, which can affect routing and cross-site navigation behavior. Risk is moderate due to new client-side cookie parsing and link localization logic but limited scope to UI navigation.

Overview
Wraps the app layout in a new LocaleProvider that detects the active locale from the NEXT_LOCALE cookie (with a defaultLocale fallback) and exposes a localizeLink helper.

Updates Navigation to memoize and render locale-adjusted navItems, and adjusts site.json by introducing defaultLocale and prefixing select navigation links with /en so they can be rewritten for other locales.

Reviewed by Cursor Bugbot for commit f168ee3. Bugbot is set up for automated code reviews on this repo. Configure here.

Comment thread util/link.js Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-intl IntlProvider) that detects locale from the NEXT_LOCALE cookie.
  • Adds a link-localization utility and updates the navigation component to rewrite locale-prefixed links.
  • Updates site.json navigation entries to include the default locale prefix and adds react-intl as 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.

Comment thread components/Navigation/index.jsx Outdated
Comment thread util/link.js Outdated
Comment thread providers/LocaleProvider.jsx Outdated
Comment thread util/link.js Outdated
Comment thread util/link.js Outdated
Comment thread components/Layout/index.jsx Outdated
Comment thread components/Navigation/index.jsx Outdated
Comment thread util/link.js Outdated
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ 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),
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit f168ee3. Configure here.

Comment thread components/providers/LocaleProvider.jsx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants