[PR #453] [MERGED] fix: honor the as parameter in router.push/replace #582

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

📋 Pull Request Information

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

Base: mainHead: fix/router-as-parameter


📝 Commits (4)

  • 715fd44 fix: stabilize instrumentation state and hydration E2E tests
  • ce20051 fix: honor the as parameter in router.push/replace
  • 3da95b4 fix: address PR review feedback
  • fad6f97 fix: remove pathname assertion that tests unimplemented behavior

📊 Changes

7 files changed (+136 additions, -39 deletions)

View changed files

📝 examples/app-router-cloudflare/instrumentation-state.ts (+28 -21)
📝 packages/vinext/src/shims/router.ts (+23 -16)
tests/e2e/helpers.ts (+5 -0)
📝 tests/e2e/pages-router/hydration.spec.ts (+4 -1)
📝 tests/e2e/pages-router/navigation.spec.ts (+46 -0)
📝 tests/fixtures/pages-basic/pages/nav-test.tsx (+29 -1)
📝 tests/fixtures/pages-basic/pages/posts/[id].tsx (+1 -0)

📄 Description

Summary

  • Fix push() and replace() silently ignoring the as parameter in both useRouter() hook and Router singleton — this broke masked URLs and legacy dynamic-route flows
  • Extract resolveNavigationTarget() helper: uses as when provided, falls back to resolveUrl(url) otherwise
  • Applied to all four call sites: useRouter().push, useRouter().replace, Router.push, Router.replace
  • Move Cloudflare instrumentation example state to globalThis for cross-module-instance visibility
  • Add waitForHydration() helper to Pages Router E2E tests to fix flaky hydration races

Test plan

  • New E2E test: router.push(url, as) uses masked URL while resolving the real route
  • New E2E test: Router.replace(url, as) uses masked URL for singleton navigation
  • Existing navigation and hydration E2E tests pass with hydration waits
  • Full Vitest suite: 68 files, 2845 tests passed
  • Full E2E suite: 476 passed
  • CI (Format, Lint, Typecheck, Vitest, 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/453 **Author:** [@NathanDrake2406](https://github.com/NathanDrake2406) **Created:** 3/11/2026 **Status:** ✅ Merged **Merged:** 3/11/2026 **Merged by:** [@james-elicx](https://github.com/james-elicx) **Base:** `main` ← **Head:** `fix/router-as-parameter` --- ### 📝 Commits (4) - [`715fd44`](https://github.com/cloudflare/vinext/commit/715fd4424bf22bc296a5d787c0307b41b45bcb38) fix: stabilize instrumentation state and hydration E2E tests - [`ce20051`](https://github.com/cloudflare/vinext/commit/ce200513747627e0a8cab9767c6f8898277f9088) fix: honor the `as` parameter in router.push/replace - [`3da95b4`](https://github.com/cloudflare/vinext/commit/3da95b448a389a029d4cc9b3b0262d2246dd5d27) fix: address PR review feedback - [`fad6f97`](https://github.com/cloudflare/vinext/commit/fad6f976244245db7a9033f5c8952afdc2e2fa1a) fix: remove pathname assertion that tests unimplemented behavior ### 📊 Changes **7 files changed** (+136 additions, -39 deletions) <details> <summary>View changed files</summary> 📝 `examples/app-router-cloudflare/instrumentation-state.ts` (+28 -21) 📝 `packages/vinext/src/shims/router.ts` (+23 -16) ➕ `tests/e2e/helpers.ts` (+5 -0) 📝 `tests/e2e/pages-router/hydration.spec.ts` (+4 -1) 📝 `tests/e2e/pages-router/navigation.spec.ts` (+46 -0) 📝 `tests/fixtures/pages-basic/pages/nav-test.tsx` (+29 -1) 📝 `tests/fixtures/pages-basic/pages/posts/[id].tsx` (+1 -0) </details> ### 📄 Description ## Summary - Fix `push()` and `replace()` silently ignoring the `as` parameter in both `useRouter()` hook and `Router` singleton — this broke masked URLs and legacy dynamic-route flows - Extract `resolveNavigationTarget()` helper: uses `as` when provided, falls back to `resolveUrl(url)` otherwise - Applied to all four call sites: `useRouter().push`, `useRouter().replace`, `Router.push`, `Router.replace` - Move Cloudflare instrumentation example state to `globalThis` for cross-module-instance visibility - Add `waitForHydration()` helper to Pages Router E2E tests to fix flaky hydration races ## Test plan - [x] New E2E test: `router.push(url, as)` uses masked URL while resolving the real route - [x] New E2E test: `Router.replace(url, as)` uses masked URL for singleton navigation - [x] Existing navigation and hydration E2E tests pass with hydration waits - [x] Full Vitest suite: 68 files, 2845 tests passed - [x] Full E2E suite: 476 passed - [x] CI (Format, Lint, Typecheck, Vitest, 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:08:54 +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#582
No description provided.