Skip to content

fix: Improve base path detection for setting a cookie - #2410

Merged
amannn merged 3 commits into
amannn:mainfrom
soroush5:fix/get-base-path-suffix
Sep 11, 2026
Merged

amannn merged 3 commits into
amannn:mainfrom
soroush5:fix/get-base-path-suffix

Conversation

@soroush5

Copy link
Copy Markdown
Contributor

I ran into this with a base path that contains the current pathname as a substring.

Repro: app mounted under /dashboard, user on /dashboard/dash, so getBasePath('/dash', '/dashboard/dash') runs. The old code did a first-occurrence replace and returned /board/dash, which is garbage and breaks navigation under that base path.

This change only strips the pathname when it's actually the trailing part of the window path, and leaves the window path untouched otherwise. I added cases for /dash under /dashboard and /doc under /docs.

Tests: the getBasePath suite in utils.test.tsx passes (18/18).

@vercel

vercel Bot commented Sep 11, 2026

Copy link
Copy Markdown

@soroush5 is attempting to deploy a commit to the next-intl Team on Vercel.

A member of the Team first needs to authorize it.

Returning the window pathname in that case would scope the locale
cookie to the current page instead of the app root. Also adds a test
for the fallback branch.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@amannn amannn changed the title fix: strip only the trailing pathname when detecting the base path fix: Improve base path detection Sep 11, 2026
@vercel

vercel Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
next-intl-docs Ready Ready Preview Sep 11, 2026 1:11pm UTC
next-intl-example-app-router Ready Ready Preview Sep 11, 2026 1:11pm UTC
next-intl-example-app-router-without-i18n-routing Ready Ready Preview Sep 11, 2026 1:11pm UTC

Request Review

Comment thread packages/next-intl/src/navigation/shared/utils.tsx Outdated
Comment thread packages/next-intl/src/navigation/shared/utils.tsx Outdated
Co-authored-by: Jan Amann <jan@amann.work>
@amannn amannn changed the title fix: Improve base path detection fix: Improve base path detection for setting a cookie Sep 11, 2026
@amannn

amannn commented Sep 11, 2026

Copy link
Copy Markdown
Owner

Added some minor changes, looks good to me now.

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.

2 participants