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 related navigation utilities/tests, then reproduce the current behavior with the smallest available test or temporary script. I’ll implement the API according to the existing conventions, run focused and broader relevant tests, review the diff, and only then submit.
- Assistant
The repository is not actually missing the prop in source: it already has an implementation, but I’m comparing it carefully with Next’s canonical
linkClickedpath. Next invokesonNavigateonly for local navigations, after preventing the browser default, and cancellation is exclusively throughevent.preventDefault()(the callback return value is ignored). I’m now checking whether vinext’s existing implementation diverges in a way that explains the CI failures, especially around callback errors, URL resolution, and router dispatch. - Assistant
The canonical Next implementation confirms that cancellation is via
preventDefault, not a special return value; however, the issue’s wording explicitly asks for return-value handling, so I’ll supportfalseas a harmless compatibility extension while preserving the documentedpreventDefault()behavior. I’ll also stop swallowing exceptions from user callbacks and ensure URL construction cannot silently suppress the callback. This makes the callback path deterministic and keeps navigation cancellation/history replacement behavior intact. - Assistant
Verification is complete: formatting, lint, and type checking pass; the focused Link navigation suite passes all 25 tests. The implementation now invokes
onNavigatereliably for local navigation, supplies the resolved destination URL, honors bothpreventDefault()and an explicitfalseguard return, and leaves external/download/modified clicks untouched. I’ll review the final diff once more and submit.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.