[PR #125] [MERGED] fix(shims): add missing URL setters to NextURL #331

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/125
Author: @harrisrobin
Created: 2/26/2026
Status: Merged
Merged: 3/4/2026
Merged by: @southpolesteve

Base: mainHead: fix/next-url-setters-v2


📝 Commits (3)

  • c371f32 fix(shims): add missing URL setters to NextURL
  • e1294ea revert build artifact to main (remove local machine paths)
  • e88c2bd Merge remote-tracking branch 'origin/main' into fix/next-url-setters-v2

📊 Changes

2 files changed (+74 additions, -3 deletions)

View changed files

📝 packages/vinext/src/shims/server.ts (+22 -3)
📝 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/125 **Author:** [@harrisrobin](https://github.com/harrisrobin) **Created:** 2/26/2026 **Status:** ✅ Merged **Merged:** 3/4/2026 **Merged by:** [@southpolesteve](https://github.com/southpolesteve) **Base:** `main` ← **Head:** `fix/next-url-setters-v2` --- ### 📝 Commits (3) - [`c371f32`](https://github.com/cloudflare/vinext/commit/c371f32cc8d39d0085b403b9598be4a766a6364c) fix(shims): add missing URL setters to NextURL - [`e1294ea`](https://github.com/cloudflare/vinext/commit/e1294eab6728ceb6f2aeb78e6341d761a6f2cf41) revert build artifact to main (remove local machine paths) - [`e88c2bd`](https://github.com/cloudflare/vinext/commit/e88c2bd28f36cd17a6ae57af4ae731381b91f70c) Merge remote-tracking branch 'origin/main' into fix/next-url-setters-v2 ### 📊 Changes **2 files changed** (+74 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/shims/server.ts` (+22 -3) 📝 `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#331
No description provided.