<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 implement the
onNavigateprop on<Link>by studying Next.js's implementation and the current vinext shim, then adding tests and the fix. - Assistant
Writing tests for
onNavigateclick behavior to verify the implementation and find gaps. - Assistant
Adding comprehensive
onNavigatetests and fixing any gaps found. - Assistant
Six of seven tests pass; implementing external link
replacehandling. - Assistant
Cleaning up the
onNavigatehandler: removing the try/catch that could silently skip the callback. - Assistant
Moving the
onNavigatetests afterrenderIsolatedLinkfor clearer structure. - Assistant
Implemented and verified
<Link onNavigate>support. Most of the behavior was already inlink.tsx; I tightened it up and added tests.What was done
Implementation (
packages/vinext/src/shims/link.tsx)onNavigatealready ran on internal link clicks. Two fixes:-
External links with
replace— Matches Next.jslinkClicked: for external URLs withreplace, callwindow.location.replace()instead of letting the browser push a new history entry. -
Removed silent try/catch — A failed URL parse could skip
onNavigateentirely. The handler now always runs for internal navigations.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.