<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 first reproduce this in the Link tests and inspect the local Next.js v16 behavior, then update the shim and run only the relevant checks.
- Assistant
The shim already contains a partial
onNavigatepath, so I’m narrowing this to contract mismatches rather than adding the prop from scratch. The local Next.js reference clone is absent; I’ll use any vendored/installed Next source and the repository’s ported test references, without network access. - Assistant
The installed Next.js 16.2.6 source confirms the contract:
onNavigateruns only for local SPA navigations, receivespreventDefault(), cancellation is controlled by that method, and the callback’s return value is ignored. I also found the shim’s callback wrapped in a broad URL-parsingtry/catch, which can suppress the handler or swallow its errors; I’m removing that coupling and adding direct contract coverage. - Assistant
The new tests now cover firing, cancellation, ignored return values, and
onClickcancellation; all 117 Link tests pass. I’m doing the final format/type/lint check and reviewing the diff for unintended changes.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.