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
I'll start by exploring the repository structure and locating the Link component implementation, then compare it with Next.js's
onNavigatebehavior. - Assistant
Let me read the Link shim and search Next.js reference for
onNavigate. - Assistant
The type exists — let me inspect how the click handler uses
onNavigateand check related tests. - Assistant
I'll switch to grep and read the click-handler section of the Link component.
- Assistant
There's already some
onNavigatelogic — I'll read the click handler and the related tests next. - Assistant
I'll read the full click-handler implementation and look up Next.js's
onNavigatecontract. - Assistant
I'll extract the exact Next.js
onNavigatehandling from both Link implementations. - Assistant
I'll look up the Next.js e2e test for
onNavigateand compare it with vinext's existing tests. - Assistant
Let me check if there's an issue with the onNavigate implementation. Looking at Next.js:
- Assistant
I'll fetch the Next.js test fixtures to see how the pages wire
onNavigate. - Assistant
Let me get the shared component and correct paths.
- Assistant
Let me get the OnNavigate.tsx component.
- Assistant
I'll inspect how Next.js wires
onClickrelative tolinkClicked. - Assistant
I'll inspect layouts and how Link is resolved in the plugin, and run the related unit tests.
- Assistant
I'll run the existing Link unit tests and draft a focused reproduction for the onNavigate behavior.
- Assistant
The test timed out. Let me try differently - maybe need vp test or something.
- Assistant
Let me try running with vp test and also check git log/diff for link.tsx. Also maybe look at CI analysis more carefully or search for known gaps.
- Assistant
Looking at git log, I don't see a specific commit for onNavigate implementation. It was added somewhere. Looking at the issue again from CI failures... I understand the issue with the
onNavigateprop on<Link>not firing in vinext. Let me break this down and address the checklist items systematically.Checklist Analysis:
- **[ ] If an error was reported in the issue description, I have successfully reproduced it.
- Assistant
I'll write a focused unit script that exercises the Next.js onNavigate cases against the current Link shim.
- Assistant
I'll inspect the download-link test setup, then write a temporary script covering the full
onNavigatecontract. - Assistant
I'll check how the URL helpers behave and whether the click handler can throw before
onNavigate. - Assistant
I'll check git history for
onNavigateand compare the built dist with the source. - Assistant
I'll look for recorded suite failures and any open work log about onNavigate.
- Assistant
There may be a remount issue during pages-router navigation. I'll inspect that path and craft a focused reproduction next.
- Assistant
I'll run Vitest directly with a clean filter so we avoids the earlier timeout.
- Assistant
Tests keep timing out without output. Something might be wrong with the test runner. Let me try without piping.
- Assistant
Vitest hangs completely. Let me check vite config.
- Assistant
Corepack is blocking on an interactive prompt — I'll enable it/non-interactive pnpm and retry the tests.
- Assistant
There's no vitest binary - use
vp test. Let me try with COREPACK_ENABLE_DOWNLOAD_PROMPT=0 - Assistant
I'll add a temporary unit test covering all of the Next.js onNavigate behaviors.
- Assistant
I'll reuse the existing link-navigation test helper so the mock matches production.
- Assistant
I'll copy the existing test harness and append complete onNavigate coverage.
- Assistant
Core cases already work; next I'll exercise the Pages Router path without the app navigation runtime.
- Assistant
Need .test.ts extension
- Assistant
I'll look for how the Next.js Deploy Suite is wired and any onNavigate-related skips.
- Assistant
I'll check how
next/linkis resolved and whether any path bypasses the shim. - Assistant
Interesting - Next.js's package.json says
next/link->./dist/client/linkwhich is the Pages link! But App Router apps usenext/dist/client/app-dir/linkthrough some webpack alias.How does Next.js reboot resolve app-dir cigar vs pages link?
- Assistant
Looking at the create-compiler-aliases - Next.js maps
linkconfig: - Assistant
Looking at Next.js API link:
- Assistant
I'll fix external
replacehandling and better align click interception with Next.js. - Assistant
Implementing external
replacehandling and tightening click interception to match Next.js more closely. - Assistant
I'll default missing
nodeNameto"A"so tests and real anchors both hit the modified-event short-circuit. - Assistant
I'll narrow the try/catch so only URL construction is guarded and
onNavigateerrors propagate. - Assistant
I'll put
anchorPropsfirst so our handlers but win over rest props, matching Next.js. - Assistant
I need to fix the anchor props order so {...anchorProps} comes first. Also update the type comment.
- Assistant
I'll verify dangerous/native schemes still short-circuit correctly and update the onNavigate prop comment.
- Assistant
mailto streams through handleClick. isAbsoluteOrProtocolRelativeUrl("mailto:...") - isAbsoluteUrl uses ABSOLUTE_URL_REGEX - mailto: matches inició. then toSameOriginAppPath - URL parsing of mailto mig...
- Assistant
I'll re-run the onNavigate parity suite and the existing link-navigation tests.
- Assistant
I'll scan remaining Link tests and types for productie gaps, then apply the package build.
- Assistant
Cleaning temp files and rebuilding the package so
distmatches the source changes. - Assistant
Hmm, git diff only shows src change, not dist. Maybe the build output is gitignored oredered differently. Let me check git status.
- Assistant
I'll remove the accidental file and try a quick related e2e for onNavigate.
- Assistant
Looking again at the issue - the analyzing agent said private onNavigate is not implemented. We found ∊ it was mostly implemented except external+replace.
- Assistant
I'll drop the
button !== 0check and match Next.js: only treat middle-click vianativeEvent.which === 2as modified. - Assistant
The last edit truncated
targetAttr— I'll restore that block. - Assistant
Good. Re-run tests to confirm. Also previously button !== Joseph and 0 would reject right clicks - now right-click button === 2 would proceed to onNavigate... but click event typically doesn't Researchfire on right-click. Fine.
- Assistant
I'll write the temp test with Node instead.
- Assistant
All 7 parity tests pass — cleaning up temp files and rebuilding.
- Assistant
I'll do a final review of the click handler, then submit.
- Assistant
sed with colon needs different syntax
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.