<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 source/tests for the exact v16 contract, then patch the shim and run only the targeted checks.
- Assistant
vpisn’t installed in this environment, so I’m using the repository’s equivalentpnpmcommands. No implementation action has been taken yet. - Assistant
The shim already contains a partial
onNavigateimplementation, but it diverges from Next.js: it exposes aURL/defaultPreventedshape and swallows URL-construction errors. I’m checking the vendored/installed Next.js artifacts and the CI-style test expectations to pin down the actual failure path before editing. - Assistant
The installed Next.js 16.2.6 implementation is authoritative here:
onNavigatereceives only{ preventDefault }; return values are ignored; callingpreventDefault()cancels router navigation. It runs only for unmodified, local, non-download client navigations. I found vinext’s partial implementation predates this report, so the regression test will specifically expose its incompatible event shape while covering the reported callback/cancellation behavior. - Assistant
The implementation now matches Next.js 16.2.6 exactly: the callback fires before navigation,
preventDefault()cancels it, return values are ignored, and callback exceptions are no longer silently swallowed. I also removed vinext-onlyevent.url/defaultPreventedassumptions from fixtures and tests. - Assistant
Unit coverage and the full repository check are green. I’m doing the two browser-level Link checks as a final parity verification for both Pages Router and App Router.
- Assistant
The browser test server built successfully, but Playwright cannot launch because the local Chromium binary is absent. I won’t download it because this task is constrained to local resources; the equivalent unit coverage and static checks are already passing.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.