<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 Next.js test suite isn't vendored. Let me check vinext's existing tests referencing
onNavigateand how the shim differs from Next.js behavior. - Assistant
Now let me check the app/pages fixture dirs and vinext's git history for when onNavigate was added:
- Assistant
onNavigatehas existed since the initial release, yet CI says it never fires. Let me read the repo docs and reproduce before assuming. - Assistant
Now let me set up a reproduction mirroring the Next.js fixture. First check the existing fixture structure:
- Assistant
Now I'll create the repro fixtures, ported from the Next.js test suite. First the App Router fixture:
- Assistant
Now the Pages Router fixture:
- Assistant
Now check the pages spec conventions, then write the two e2e specs:
- Assistant
Now run the new specs against dev servers to see what actually fails:
- Assistant
While that runs, let me monitor the output:
- Assistant
While that runs, implement the fix in the Link shim mirroring Next.js's
linkClicked: - Assistant
Now add a unit test for the external+replace behavior following the existing pattern:
- Assistant
Unit tests pass. Let me verify the new test actually fails without the shim fix (guard against a vacuous test):
- Assistant
The pages-router server is still building. Meanwhile, run the repo checks on the changed files:
- Assistant
The fixtures resolve shims from
dist/, so I need to rebuild vinext before rerunning e2e. Let me wait for the pages run to finish first: - Assistant
All consistent. Waiting for the pages-router run to produce output — nothing else to change until then.
- Assistant
While the pre-fix pages-router run finishes, here's where things stand:
Diagnosis so far (verified by running the ported Next.js suite locally):
onNavigatedoes fire in vinext — 6 of 7 App Router tests passed on unmodifiedmain. The issue title overstates the failure.- The real gap: external links with the
replaceprop. Next.js'slinkClickeddoese.preventDefault(); location.replace(href)for non-local URLs whenreplaceis set (browser default always pushes). vinext just returned early, so history got a push instead of a replace — reproduced locally (history.length3 vs expected 2).
Fix applied in
packages/vinext/src/shims/link.tsx:558-575, plus a unit test (verified red→green) and ported e2e fixtures/specs for both routers. - Assistant
All 7 pages tests failed at hydration wait — the
/on-navigatepage itself is broken. Let me investigate with a dev server: - Assistant
Fix is in dist (comments stripped by tsdown). Now rerun both e2e specs:
- Assistant
App Router now 7/7. Pages run ongoing. Fix the smoke-check syntax:
- Assistant
All 14 e2e tests pass. Since I modified the shared
_app.tsxfixture, run the full pages-router e2e project plus related unit tests to check for regressions: - Assistant
Unit tests: 1138 passed. Waiting on the full pages-router e2e run.
- Assistant
Transient
EAGAIN— resource contention with the concurrent e2e run. I'll retry the check after it finishes. - Assistant
Still building. I'll pick up when the run completes.
- Assistant
Both diffs look right. Waiting for the full pages-router e2e suite to confirm no regressions from the
_app.tsxchange — I'll report back when it completes. - Assistant
Full pages-router suite still running (output is piped through
tail, so it arrives at completion). The active monitor will notify when the summary appears. - Assistant
While waiting, retry the check that hit EAGAIN earlier:
- Assistant
Still
EAGAIN—vp checkspawns 128 worker processes and the box is saturated by the running e2e suite. I'll run it once the suite finishes (it passed earlier on the same files; only the_app.tsxuseRouteredit is newly unchecked). Standing by for the monitor. - Assistant
No live browsers — the runner wedged during the earlier process-spawn saturation. Kill and restart it now that the machine is quiet:
- Assistant
The checker keeps crashing while the e2e build runs concurrently. I'll run it after the suite completes — waiting on the background run now.
- Assistant
Standing by for the pages-router e2e completion notification; then I'll do the final
vp checkand summarize. - Assistant
91 passed, 3 flaky (pthread resource noise from the environment, passed on retry), 0 failed — the
_app.tsxchange is safe. Final checks: - Assistant
All green. One non-obvious compat gap surfaced during this work is worth remembering:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.