<Link onNavigate> prop not implemented This issue was created by an agent analysing CI…
- User
<Link onNavigate>prop not implementedThis issue was created by an agent analysing CI failures from the Next.js Deploy Suite (vinext
mainvs Next.jsv16.2.6, 2026-05-20).Problem
The
onNavigatecallback prop on<Link>(added in Next.js 15) does not fire. Tests that rely ononNavigateto detect navigations, intercept them, or track click state all fail.Specific failures include:
onNavigatecallback never fires on click- Click state tracking broken (link thinks it was never clicked)
- History state replacement via
onNavigatereturn value not working
Estimated Impact
~8 test failures.
Affected Test Suites
test/e2e/link-on-navigate-prop/index.test.ts(8 failures)
Recommendation
-
Reproduce first in vinext's own test suite. Add a test with
<Link href="/page" onNavigate={(e) => ...}>and verify the callback fires on click. Confirm it does not. -
Study the Next.js implementation. Search
.nextjs-ref/packages/next/src/client/link.tsxforonNavigateto understand the API contract: when the callback fires, what arguments it receives, and how the return value affects navigation (e.g., preventing default, replacing history state). -
Implement
onNavigatein thenext/linkshim. The Link component needs to callonNavigatebefore performing the navigation and respect the return value.
Interface
No new interfaces are introduced.
- Assistant
I'll implement the
onNavigateprop on<Link>by studying Next.js's behavior and the current vinext shim, then adding tests and the fix. - Assistant
I'll add tests for the missing
onNavigatecases and run them to see what's failing. - Assistant
Implementing remaining gaps: aligning external-link
replacebehavior with Next.js and hardeningonNavigateso it isn't skipped by the try/catch. - Assistant
Implemented and hardened the
<Link onNavigate>prop to match Next.js behavior.What changed
onNavigatewas already partially present inlink.tsx, but the click handler had a few parity gaps:- Silent skip risk —
onNavigatewas inside atry/catcharound URL construction. If parsing failed, the callback was skipped while navigation still proceeded. - External
replacelinks — Next.js callslocation.replace()for external URLs withreplace; vinext returned early without doing that. - Local vs external detection — Added
isLocalURL()(mirroring Next.js) for consistent routing decisions.
Implementation
packages/vinext/src/shims/link.tsx- Uses
isLocalURL()before intercepting clicks - Handles external
replaceviawindow.location.replace() - Calls
onNavigatewith aNavigateEvent(url,preventDefault(),defaultPrevented) before navigation - Respects
preventDefault()on the navigate event to cancel navigation (for view transitions / locked navigation)
packages/vinext/src/shims/url-utils.ts- Added
isLocalURL()helper
Tests added
Ported cases from Next.js
link-on-navigate-prope2e intotests/link-navigation.test.ts:onNavigatefires on internal navigation (App + Pages Router)preventDefault()blocks navigation- Modifier keys,
download,target="_blank", and external links do not callonNavigate - External
replacelinks calllocation.replace()without callingonNavigate
All 124 link-related unit tests pass.
- Silent skip risk —
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- fable-5Compare side by side →
- fable-5Compare side by side →