<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
Implementing
onNavigateon the Link shim. I'll review the current implementation and Next.js's API contract first. - Assistant
Adding tests ported from Next.js's
link-on-navigate-propsuite to verify whetheronNavigateworks. - Assistant
Hardening
onNavigateand aligning external-linkreplacebehavior with Next.js. Core internal navigation already works; fixing the remaining gaps and tests. - Assistant
Implemented and hardened
<Link onNavigate>support. The callback was already wired inlink.tsx; the gaps were robustness, Next.js parity for externalreplace, and test coverage.Changes
packages/vinext/src/shims/link.tsx-
onNavigatealways fires — Removed the try/catch that could skip the callback when URL parsing failed. The handler now uses fallback URL resolution soonNavigateis always invoked for internal navigations. -
External links with
replace— Matches Next.js: for truly external URLs withreplace, callswindow.location.replace(href)instead of letting the browser push a history entry.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.