<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 reference implementation and tests, then patch the shim and run only the relevant checks.
- Assistant
vpisn’t installed in this environment, so I’m using the repository’s equivalentpnpmcommands. I’m also checking the worktree before editing so existing changes remain untouched. - Assistant
The installed local Next.js package is exactly 16.2.6, so it provides the authoritative implementation without network access. Its contract is narrower than the current shim:
onNavigatereceives onlypreventDefault(), its return value is ignored, andpreventDefault()cancels router navigation. I found vinext had a partial implementation, but it wrapped the callback in URL construction/error swallowing and lacked positive/cancellation coverage. I’m aligning it exactly and porting the relevant behavioral cases. - Assistant
The first run exposed a test-harness interaction, not a Link regression: importing React’s JSX development runtime while
NODE_ENV=productionpoisoned the mocked module cache, causing all later Link tests to fail withjsxDEV is not a function. I’m keeping these navigation tests environment-neutral; production mode is irrelevant to click handling. - Assistant
The targeted Link suites now pass, including callback order, cancellation, ignored return values, and existing native/download behavior. I’m running the broader shim suite once because this changes a
next/*shim, then I’ll hand off the final diff.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.