[PR #516] [MERGED] fix: add basePath and locale properties to NextURL #638

Closed
opened 2026-05-06 13:09:14 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/516
Author: @NathanDrake2406
Created: 3/13/2026
Status: Merged
Merged: 3/18/2026
Merged by: @james-elicx

Base: mainHead: fix/nexturl-basepath-locale


📝 Commits (6)

  • 79a24b0 fix: add basePath and locale properties to NextURL
  • 93e8084 fix: address review feedback on NextURL
  • 81e258d fix: address second round of review feedback
  • 46ec93f fix: address third round of review feedback on NextURL
  • a365cf8 fix: locale setter resets to defaultLocale on falsy value when i18n configured
  • 57b8534 Update packages/vinext/src/shims/server.ts

📊 Changes

7 files changed (+467 additions, -14 deletions)

View changed files

📝 packages/vinext/src/entries/app-rsc-entry.ts (+2 -1)
📝 packages/vinext/src/entries/pages-server-entry.ts (+2 -1)
📝 packages/vinext/src/index.ts (+1 -0)
📝 packages/vinext/src/server/middleware.ts (+9 -1)
📝 packages/vinext/src/shims/server.ts (+132 -8)
📝 tests/__snapshots__/entry-templates.test.ts.snap (+4 -2)
📝 tests/shims.test.ts (+317 -1)

📄 Description

Summary

  • NextURL was missing basePath, locale, defaultLocale, and locales properties that Next.js documents and real middleware depends on
  • Locale is extracted from the pathname on construction (case-insensitive matching), and href/toString() reconstruct the full URL with locale + basePath prefixes — matching Next.js formatPathname() semantics
  • Config is threaded through NextRequestNextURL in all three middleware construction paths (dev runner, App Router RSC entry codegen, Pages Router prod entry codegen)
  • locale setter validates against configured locales (throws TypeError on invalid, matching Next.js)
  • locales getter returns a defensive copy to prevent internal mutation
  • clone() passes config through the constructor for proper re-analysis

Test plan

  • 21 new unit tests covering basePath, locale detection, case-insensitive matching, href/toString() reconstruction, locale setter validation, clone preservation, and NextRequest integration
  • All 686 existing shims tests pass (no regressions)
  • All 419 app-router + pages-router tests pass
  • Entry-templates snapshots updated and passing
  • Typecheck clean (tsgo --noEmit)
  • Lint clean (oxlint)
  • CI: full Vitest suite
  • CI: Playwright E2E

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/cloudflare/vinext/pull/516 **Author:** [@NathanDrake2406](https://github.com/NathanDrake2406) **Created:** 3/13/2026 **Status:** ✅ Merged **Merged:** 3/18/2026 **Merged by:** [@james-elicx](https://github.com/james-elicx) **Base:** `main` ← **Head:** `fix/nexturl-basepath-locale` --- ### 📝 Commits (6) - [`79a24b0`](https://github.com/cloudflare/vinext/commit/79a24b0e7e406ffc10fe3d343f6c0259e9735bce) fix: add basePath and locale properties to NextURL - [`93e8084`](https://github.com/cloudflare/vinext/commit/93e80849f7a85b734883fd8577130717e36a0c39) fix: address review feedback on NextURL - [`81e258d`](https://github.com/cloudflare/vinext/commit/81e258d5702d678caafd599fab6df22c355edabe) fix: address second round of review feedback - [`46ec93f`](https://github.com/cloudflare/vinext/commit/46ec93f8ea76dde21f52cbdd204876fb018143a0) fix: address third round of review feedback on NextURL - [`a365cf8`](https://github.com/cloudflare/vinext/commit/a365cf88089cc2d3190f0ca4bccbd41075820fa9) fix: locale setter resets to defaultLocale on falsy value when i18n configured - [`57b8534`](https://github.com/cloudflare/vinext/commit/57b85344be58d51f8c983d57cd24a877626a3b35) Update packages/vinext/src/shims/server.ts ### 📊 Changes **7 files changed** (+467 additions, -14 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/entries/app-rsc-entry.ts` (+2 -1) 📝 `packages/vinext/src/entries/pages-server-entry.ts` (+2 -1) 📝 `packages/vinext/src/index.ts` (+1 -0) 📝 `packages/vinext/src/server/middleware.ts` (+9 -1) 📝 `packages/vinext/src/shims/server.ts` (+132 -8) 📝 `tests/__snapshots__/entry-templates.test.ts.snap` (+4 -2) 📝 `tests/shims.test.ts` (+317 -1) </details> ### 📄 Description ## Summary - `NextURL` was missing `basePath`, `locale`, `defaultLocale`, and `locales` properties that [Next.js documents](https://nextjs.org/docs/app/api-reference/functions/next-request#nexturl) and real middleware depends on - Locale is extracted from the pathname on construction (case-insensitive matching), and `href`/`toString()` reconstruct the full URL with locale + basePath prefixes — matching Next.js `formatPathname()` semantics - Config is threaded through `NextRequest` → `NextURL` in all three middleware construction paths (dev runner, App Router RSC entry codegen, Pages Router prod entry codegen) - `locale` setter validates against configured locales (throws `TypeError` on invalid, matching Next.js) - `locales` getter returns a defensive copy to prevent internal mutation - `clone()` passes config through the constructor for proper re-analysis ## Test plan - [x] 21 new unit tests covering basePath, locale detection, case-insensitive matching, `href`/`toString()` reconstruction, locale setter validation, clone preservation, and NextRequest integration - [x] All 686 existing shims tests pass (no regressions) - [x] All 419 app-router + pages-router tests pass - [x] Entry-templates snapshots updated and passing - [x] Typecheck clean (`tsgo --noEmit`) - [x] Lint clean (`oxlint`) - [ ] CI: full Vitest suite - [ ] CI: Playwright E2E --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 13:09:14 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#638
No description provided.