<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
The shim already has onNavigate code. Let me check git history and existing tests to see the current state.
- Assistant
Now I'll add reproduction tests ported from the Next.js e2e suite to
tests/link-navigation.test.ts: - Assistant
The contract matches vinext's
toSameOriginAppPath. Now implement the fix in the Link shim: - Assistant
Now fix the test-environment gap in my Pages Router test (the fallback path uses
PopStateEvent, which doesn't exist in the Node test env): - Assistant
All 32 tests pass, but the async Pages Router fallback settles after the test's globals are unstubbed. Let me drain with macrotasks instead:
- Assistant
Unit coverage is in place. Now run the broader relevant tests and repo checks:
- Assistant
All checks pass. Let me run the full test suite to make sure nothing else regressed:
- Assistant
The full suite shows errors — let me check whether they're pre-existing on main or caused by my change:
- Assistant
While the full suite runs, let me review the final diff:
- Assistant
The suite is still running (it's a ~6 min serial suite). I'll wait for the background task to finish before concluding.
- Assistant
Waiting for the suite to finish — the background watcher will notify when the summary line appears.
- Assistant
The full suite is still running. I'll pause here — the background watchers will notify when it completes, and I'll verify the final summary then.
- Assistant
The run is alive (started ~03:57, heavy serial suite). I'll wait for its completion notification.
- Assistant
I'll let the background watchers run — they'll notify when the suite finishes.
- Assistant
Waiting on the full-suite run to complete (background tasks
b6rrydapw/bgizs0mz3will report back). Current status of the fix itself:packages/vinext/src/shims/link.tsx— external links withreplacenowpreventDefault()+window.location.replace(href)(matching Next.jslinkClicked), andonNavigatecallbacks that throw now propagate and abort navigation instead of being swallowed.tests/link-navigation.test.ts— 7 new tests ported fromtest/e2e/link-on-navigate-prop/index.test.ts, all passing (the external-replace one failed before the fix, confirming the reproduction).pnpm run checkpasses.
- Assistant
Passes standalone (3/3). Done — final state:
Result
The issue's headline symptom (
onNavigatenever firing) had already been fixed onmainby earlier commits (#483, #1262, #1264), but reproducing the ported Next.js suite exposed two remaining gaps in thenext/linkshim, now fixed:Changes
packages/vinext/src/shims/link.tsx- External links with
replacedid nothing special — the browser default pushed a new history entry, failing theexternal-link-with-replacetest. Next.js's does for non-local URLs with ; the shim now matches ().
- External links with
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.