mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #336] [MERGED] fix: normalize same-origin absolute URLs for client-side navigation #488
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#488
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/336
Author: @Divkix
Created: 3/8/2026
Status: ✅ Merged
Merged: 3/8/2026
Merged by: @james-elicx
Base:
main← Head:fix/link-same-origin-absolute-url📝 Commits (3)
0f91200fix: normalize same-origin absolute URLs for client-side navigation4f0ac02fix: handle protocol-relative URLs in toSameOriginPath()9c2a132Update tests/link.test.ts📊 Changes
5 files changed (+193 additions, -33 deletions)
View changed files
📝
packages/vinext/src/shims/link.tsx(+25 -9)📝
packages/vinext/src/shims/navigation.ts(+14 -7)📝
packages/vinext/src/shims/router.ts(+33 -16)➕
packages/vinext/src/shims/url-utils.ts(+26 -0)📝
tests/link.test.ts(+95 -1)📄 Description
Summary
Fixes #335
toSameOriginPath()utility that extracts the local path (pathname + search + hash) from a same-origin absolute URL, returningnullfor truly external URLs or server-side contextslink.tsxhandleClick()and prefetch paths to normalize same-origin URLs before the external URL bail-outnavigation.tsnavigateImpl()(App Router) to normalize before external URL checkrouter.tspush()/replace()in both theuseRouterhook andRoutersingleton (Pages Router)Root Cause
isExternalUrl()treated any URL with a scheme as external — no same-origin comparison. When<Link href="http://localhost:3000/about">was used and the origin matched, it triggered a full page reload instead of SPA navigation.Test plan
toSameOriginPath()— same-origin returns local path, cross-origin returns null, server returns null, preserves search/hash<Link>with absolute URLsisExternalUrl()still correctly identifies truly external URLspnpm test tests/link.test.ts— 35 tests passpnpm test tests/shims.test.ts— 568 tests passpnpm run typecheck— cleanpnpm run lint— clean🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.