ISSUE DESCRIPTION <Link onNavigate> prop not implemented This issue was created by an…
- User
ISSUE DESCRIPTION
<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.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusor commands. However you don't need to use or before submitting your changes. In fact, only submits currently unstaged changes because it uses to get the changes that need to be submitted. - Assistant
I’ll inspect the repository’s Link implementation and relevant tests, then compare the expected Next.js API behavior with the local routing abstractions. I’ll reproduce the missing callback if practical, implement the smallest compatible change, run focused tests (and broader checks if available), and review the final diff for edge cases before submitting.
- Assistant
The implementation is present in the current source, so the reported failure is not reproducible as a completely missing prop. Comparing it with Next shows two compatibility gaps worth correcting: the public shim declaration does not expose the
url/defaultPreventedevent shape used by this implementation, and the callback result is discarded despite the issue’s explicit requirement to respect it. I’ll make cancellation explicit and keep callback errors observable rather than silently swallowing them. - Assistant
The first edit command could not run because this environment lacks Python; no files were changed. I’ll apply the same targeted edits using Node (already required by the repository), then typecheck and run focused tests.
- Assistant
The source now constructs a navigation event with the resolved absolute URL, exposes its cancellation state, invokes
onNavigateimmediately before router navigation, and stops navigation when eitherpreventDefault()or afalsecallback result is used. The ambientnext/linkdeclaration now matches that event shape.tsc --noEmitcompleted without diagnostics, andgit diff --checkis clean; Vitest could not be launched because the checkout has no local Vitest binary and Corepack attempted an unavailable package download. I’m submitting the focused change.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.