mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #393] [MERGED] fix: enforce segment boundaries for basePath stripping and redirect prefixing #537
Labels
No labels
enhancement
enhancement
good first issue
help wanted
nextjs-tracking
nextjs-tracking
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vinext#537
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/cloudflare/vinext/pull/393
Author: @JaredStowell
Created: 3/10/2026
Status: ✅ Merged
Merged: 3/10/2026
Merged by: @james-elicx
Base:
main← Head:jstowell/fix-basepath-segment-boundary📝 Commits (4)
a76caa8Update deploy basePath strippingb2aa9d3Fix redirect basePath handling3885f97Document basePath segment fix36a0fddFix external redirect basePath📊 Changes
13 files changed (+194 additions, -56 deletions)
View changed files
📝
packages/vinext/src/deploy.ts(+19 -5)📝
packages/vinext/src/entries/app-rsc-entry.ts(+4 -2)📝
packages/vinext/src/index.ts(+14 -2)📝
packages/vinext/src/server/prod-server.ts(+12 -8)📝
packages/vinext/src/server/request-pipeline.ts(+3 -6)📝
packages/vinext/src/shims/navigation.ts(+3 -9)📝
packages/vinext/src/shims/router.ts(+3 -9)➕
packages/vinext/src/utils/base-path.ts(+24 -0)📝
tests/__snapshots__/entry-templates.test.ts.snap(+24 -12)📝
tests/app-router.test.ts(+2 -1)📝
tests/deploy.test.ts(+11 -2)📝
tests/features.test.ts(+49 -0)📝
tests/request-pipeline.test.ts(+26 -0)📄 Description
This fixes incorrect
basePathhandling when a path only shares a string prefix with the configured base path, instead of matching on a path-segment boundary.Before this change, vinext treated any pathname beginning with the
basePathstring as being inside the base path. WithbasePath: "/app", that meant:/app/aboutcorrectly stripped to/about/appcorrectly stripped to//application/aboutincorrectly stripped as well/app2incorrectly stripped as wellThat was not limited to request-path stripping. Redirect destination handling had the same bug: a destination like
/application/aboutwas incorrectly treated as already being under/app, so vinext would emit/application/aboutinstead of/app/application/about.In the server flow, the stripped value was fed back into URL/request handling, so
/application/aboutcould normalize to"/lication/about"and potentially collide with a real in-app route. In other words, a request outside the configured base path could be misrouted into an unrelated page if the suffix happened to exist.The fix centralizes basePath handling into shared helpers:
hasBasePath()only matches when the pathname is exactly equal to the base path, or starts withbasePath + "/"stripBasePath()only strips in those casesImplementation details:
Test coverage added:
basePathcoverage such as/docs/v2vs/docs/v20/application/aboutmust not resolve to/app/lication/about/app/redircorrectly redirects to/app/application/aboutValidation run:
pnpm test tests/features.test.ts -t "basePath HTTP routing"pnpm test tests/request-pipeline.test.ts tests/deploy.test.ts tests/app-router.test.ts -t "basePath"pnpm test tests/entry-templates.test.ts -upnpm run typecheck🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.