<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 reproduce this in the existing Link tests, inspect the local Next.js v16 reference for the exact callback contract, then update the shim and run only the relevant checks. I’ll also verify whether keyboard/programmatic paths share the same click handler.
- Assistant
vpis not installed in this environment, so I’ll use the repository’spnpmequivalents for installation and validation. The local source and test inspection can proceed without changing dependencies. - Assistant
This container is also missing
rg; I’m falling back tofind/grep. The dependency tree is already current, and I’m checking the worktree before editing so unrelated user changes remain untouched. - Assistant
The current shim already contains an older
onNavigateimplementation, so the failure is subtler than a missing prop. Comparing it with bundled Next.js 16.2.6 shows a contract mismatch: Next.js exposes onlypreventDefault()and invokes the callback for local unmodified navigations; vinext added nonstandardurl/defaultPreventedfields and wraps the callback in a catch that can swallow user exceptions. I’m now porting the actual behavioral cases around firing, cancellation, modified/external/download clicks, and navigation requested from inside the callback. - Assistant
The focused behavioral coverage is now in place. The key implementation correction is that user callback errors are no longer mistaken for URL-parsing failures and silently discarded; cancellation is tracked separately, while callback return values remain ignored exactly as Next.js 16.2.6 does. The tests also cover
replace, click cancellation, modified/middle/targeted clicks, and callback ordering. - Assistant
All 121 focused Link tests pass. I’m doing the final repository format/type-aware lint checks now; because the global
vpexecutable is absent, these run through the project’s package scripts (which resolve its local toolchain).
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.