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.
Interface
No new interfaces are introduced.
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 call ) using or 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
All 25 tests pass in link-navigation.test.ts, including onNavigate tests. Let's check shims.test.ts for the onNavigate section too.
Assistant
Build succeeded. Now let's start the production server and test with playwright directly.
Assistant
Works correctly in production build too. Let's clean up the server and verify a few more edge scenarios in production mode (prevent, history replace, blank).
Assistant
Now let's rebuild and test this transition pattern in dev mode.
Assistant
Good, all cleaned up. Let's restart the dev server fresh.
Assistant
Now let's run the transition-link check.
Assistant
Right — App Router uses
__VINEXT_RSC_ROOT__, not__VINEXT_ROOT__. Let's fix the check script.Assistant
External links correctly do NOT fire onNavigate, matching Next.js spec. Everything checks out. Let's clean up all temporary files now.
Assistant
All 1042 tests pass (those stderr logs are expected error-path logging from unrelated image-optimization tests). Let's also run the pages-router and app-router e2e suites for link-related specs to reconfirm everything remains intact.
Assistant
All existing tests pass. Let's do a final cleanup check and verify the working tree is clean.
Assistant
Assistant
The
onNavigateprop on<Link>is already fully and correctly implemented in this repository at the currentHEAD(5748be3). My investigation:- Located the implementation in
packages/vinext/src/shims/link.tsx(lines ~578-601), which callsonNavigatewith aNavigateEvent(url,preventDefault(),defaultPrevented) before performing client-side navigation, and aborts navigation ifpreventDefault()was called — matching the realnext@16.2.6package'sapp-dir/link.jsandlink.js(node_modules/.../next/dist/client/...) contract exactly. - Confirmed via / that the relevant fix commits (e.g. "Fix Link onNavigate URL resolution for relative hrefs") are already merged into .
- Located the implementation in
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.