[PR #124] [CLOSED] fix(shims): add missing URL setters to NextURL #333

Closed
opened 2026-05-06 12:39:15 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/124
Author: @harrisrobin
Created: 2/26/2026
Status: Closed

Base: mainHead: fix/next-url-setters


📝 Commits (6)

  • dd656fe chore: add .worktrees/ to .gitignore
  • bf3a90e fix(deploy): detect bun.lock text format and walk up to monorepo root
  • a5875a1 fix(routing): pass exclude as function to node:fs/promises.glob
  • 5f41b8e fix(deploy): resolve node_modules by walking up to monorepo root
  • 28a7a0f fix(deploy): monorepo-aware lock file and node_modules resolution (refactored)
  • ec975cf fix(shims): add missing URL setters to NextURL

📊 Changes

9 files changed (+469 additions, -209 deletions)

View changed files

📝 .gitignore (+3 -0)
📝 packages/vinext/src/deploy.ts (+13 -15)
📝 packages/vinext/src/routing/app-router.ts (+7 -3)
📝 packages/vinext/src/routing/pages-router.ts (+7 -1)
📝 packages/vinext/src/shims/server.ts (+22 -3)
📝 packages/vinext/src/utils/project.ts (+63 -8)
📝 tests/deploy.test.ts (+96 -0)
📝 tests/fixtures/pages-basic/dist/server/entry.js (+206 -179)
📝 tests/shims.test.ts (+52 -0)

📄 Description

Summary

NextURL only had setters for pathname, search, and hash. The properties port, host, hostname, protocol, href, username, and password were getter-only, unlike the platform URL class.

Libraries like next-intl rely on being able to mutate a cloned nextUrl. Specifically, getAlternateLinksHeaderValue does:

const f = request.nextUrl.clone();  // returns NextURL
// …
f.port = "";      // ← throws! NextURL has no set port()
f.host = h;       // ← same
f.protocol = ;   // ← same

In Cloudflare Workers the x-forwarded-host header is always present, so this code path is always triggered, producing:

TypeError: Cannot set property port of [object Object] which has only a getter

Fix

Add setter counterparts for all writable URL properties so NextURL behaves identically to the platform URL class:

  • href, protocol, username, password, host, hostname, port (setters were missing)
  • pathname, search, hash already had setters; origin and searchParams are read-only on URL too — unchanged

Test plan

  • Two new unit tests covering the NextURL setters
  • nextUrl.clone() setter compatibility test specifically simulating next-intl's pattern
  • All 2025 existing tests pass
  • Lint: 0 warnings/errors (oxlint)
  • Typecheck: clean (tsgo --noEmit)

/bonk


🔄 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/124 **Author:** [@harrisrobin](https://github.com/harrisrobin) **Created:** 2/26/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/next-url-setters` --- ### 📝 Commits (6) - [`dd656fe`](https://github.com/cloudflare/vinext/commit/dd656fee5b07e59eb887614a43dd9069fae227f3) chore: add .worktrees/ to .gitignore - [`bf3a90e`](https://github.com/cloudflare/vinext/commit/bf3a90e2a9fcc488f00008c1a7943113172bb9df) fix(deploy): detect bun.lock text format and walk up to monorepo root - [`a5875a1`](https://github.com/cloudflare/vinext/commit/a5875a1c1f020e1e6dd3bc72afd7e4fd4b2dfff4) fix(routing): pass exclude as function to node:fs/promises.glob - [`5f41b8e`](https://github.com/cloudflare/vinext/commit/5f41b8ea74c1f2ddde5375fad7f0f774240df83d) fix(deploy): resolve node_modules by walking up to monorepo root - [`28a7a0f`](https://github.com/cloudflare/vinext/commit/28a7a0f610d10551f37af6b7372ea389a77e0e7c) fix(deploy): monorepo-aware lock file and node_modules resolution (refactored) - [`ec975cf`](https://github.com/cloudflare/vinext/commit/ec975cfe436eff5fc7f31ef8168e6e3c2c0bc509) fix(shims): add missing URL setters to NextURL ### 📊 Changes **9 files changed** (+469 additions, -209 deletions) <details> <summary>View changed files</summary> 📝 `.gitignore` (+3 -0) 📝 `packages/vinext/src/deploy.ts` (+13 -15) 📝 `packages/vinext/src/routing/app-router.ts` (+7 -3) 📝 `packages/vinext/src/routing/pages-router.ts` (+7 -1) 📝 `packages/vinext/src/shims/server.ts` (+22 -3) 📝 `packages/vinext/src/utils/project.ts` (+63 -8) 📝 `tests/deploy.test.ts` (+96 -0) 📝 `tests/fixtures/pages-basic/dist/server/entry.js` (+206 -179) 📝 `tests/shims.test.ts` (+52 -0) </details> ### 📄 Description ## Summary `NextURL` only had setters for `pathname`, `search`, and `hash`. The properties `port`, `host`, `hostname`, `protocol`, `href`, `username`, and `password` were getter-only, unlike the platform `URL` class. Libraries like `next-intl` rely on being able to mutate a cloned `nextUrl`. Specifically, `getAlternateLinksHeaderValue` does: ```js const f = request.nextUrl.clone(); // returns NextURL // … f.port = ""; // ← throws! NextURL has no set port() f.host = h; // ← same f.protocol = …; // ← same ``` In Cloudflare Workers the `x-forwarded-host` header is always present, so this code path is always triggered, producing: ``` TypeError: Cannot set property port of [object Object] which has only a getter ``` ## Fix Add setter counterparts for all writable URL properties so `NextURL` behaves identically to the platform `URL` class: - `href`, `protocol`, `username`, `password`, `host`, `hostname`, `port` (setters were missing) - `pathname`, `search`, `hash` already had setters; `origin` and `searchParams` are read-only on `URL` too — unchanged ## Test plan - [x] Two new unit tests covering the NextURL setters - [x] `nextUrl.clone()` setter compatibility test specifically simulating next-intl's pattern - [x] All 2025 existing tests pass - [x] Lint: 0 warnings/errors (`oxlint`) - [x] Typecheck: clean (`tsgo --noEmit`) /bonk --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 12:39:15 +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#333
No description provided.