<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 trace the local Next.js tests and implementation first, then add focused vinext tests and update the Link shim to match the observed contract.
- Assistant
The repository’s preferred
vpCLI isn’t installed in this environment, so I’m using the existing pnpm workflow and continuing with the required local reference search. - Assistant
rgis also unavailable, so I’m falling back tofind/grep. The working tree is clean; no user edits need to be preserved around this change. - Assistant
The exact installed Next.js 16.2.6 implementation is available locally. Its contract is narrower than the issue’s wording:
onNavigatereceives{ preventDefault() }; callback return values are ignored. Navigation is canceled only when that method is called, and the callback is skipped for modified, download, external, target-window, or already-prevented clicks. Vinext has a partial implementation, but its current tests mostly reconstruct a fake event instead of exercising<Link>itself, so I’m tightening behavior against the actual component path. - Assistant
The focused tests now exercise the real Link click handler: callback delivery, cancellation via
preventDefault, ignored return values, and all major native-navigation exclusions. I also removed the catch that could silently suppressonNavigate; the callback now runs as part of every accepted client navigation before router/history mutation. - Assistant
The targeted Link suites pass: 120 tests across
link-navigationandlink. I’m running the repository checks now to catch formatting, lint, and type issues introduced by the new callback-path coverage. - Assistant
Unit tests remain green after formatting. The two existing browser suites that exercise
onNavigatein App Router and Pages Router are still running; I’m waiting for those final parity checks. - Assistant
The browser run was blocked before tests executed by an existing fixture/toolchain startup failure (
jsx-in-js/page.jsdependency scan, followed by Miniflare runtime startup). The focused unit coverage and full format/lint/type check are green; I’m doing a final diff review and ensuring the failed server startup left no generated changes.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.