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 finding the Link component implementation, plus the Next.js reference for
onNavigate. - Assistant
Let me examine the Link shim and search for the Next.js
onNavigateimplementation. - Assistant
There's already a type for
onNavigate. Let me see how it's used in the click handler and inspect Next.js's implementation. - Assistant
rg is not found? That's odd. Let me use grep instead.
- Assistant
There's already some onNavigate code — let me compare vinext's implementation with Next.js and check the tests.
- Assistant
Let me read vinext's onNavigate click handling and look at related tests.
- Assistant
Looking at the Next.js implementation more carefully. The issue mentions:
- Assistant
Let me check the remainder of the click path and the onNavigate unit tests to see what's already covered.
- Assistant
There's already an onNavigate implementation and tests. Let me inspect the Next.js e2e suite to understand the exact expected contract.
- Assistant
Let me look up the Next.js e2e test source and any docs related to this in the repo.
- Assistant
Let me fetch the test fixtures to understand the expected API contract.
- Assistant
Let me get the shared OnNavigate.tsx fixture.
- Assistant
Looking at external-link replace handling and how the next/link module is wired.
- Assistant
Looking at the issue again more carefully: I need to address the
onNavigateprop issue in the Next.js Link shim. Let me break this down systematically.First, let me check the current implementation of the Link component to see how
onNavigateis handled: I should look at the source code to understand the current state. - Assistant
Looking at whether dist is stale and how legacyBehavior/
onClickinteract. - Assistant
Let me check the e2e relative-query test and run the link unit tests to see current behavior.
- Assistant
Let me run a narrower unit test and inspect pull request context around the original issue.
- Assistant
Vitest is timing out. Let me check vite config and try differently.
- Assistant
Let me check the vitest config and try running with vp.
- Assistant
Let me try running with timeout and vp test.
- Assistant
The test is hanging. Let me diagnose why.
- Assistant
Even a nonmatching test hangs. Something is wrong with the test runner — I'll try a simpler invoke.
- Assistant
Let me look for related issue trackers and verify the external-replace gap is the main missing piece.
- Assistant
There's a nextjs-deploy-suite workflow. Let me check how it works and if there are any known gaps related to onNavigate.
- Assistant
Let me dig deeper into the link handleClick and compare of every edge case with Next.js. Perhaps the issue is that
toSameOriginAppPathtreats external incorrectly, or the absolute URL isn't resolved properly. - Assistant
Looking at the Next.js app router linkClicked again carefully:
- Assistant
I found a potential bug:
anchorPropsis spread afteronClick. Checking the deploy suite and more carefully comparing. - Assistant
I'll write a comprehensive standalone reproduction script for onNavigate edge cases.
- Assistant
Looking at what might have caused the original CI failures more carefully carefully.
- Assistant
Let me check how vinext substitutes next packages in the deploy suite.
- Assistant
Let me check the actual CI run for failure details.
- Assistant
Let me download logs for one of the jobs and search for on-navigate.
- Assistant
Logs may Not be accessible without auth. Let me try finding Reports in the repo.
- Assistant
Let me look at the layout for the link-on-navigate test - maybe they need a client component wrapper. Also check if there's something wrong with onClick + hydration.
- Assistant
What if absoluteFullHref is empty or bad? toBrowserNavigationHref for
/app-router/subpagereturns thatotoxicity.new URL("/app-router/subpage", origin)works.What if __basePath is undefined binding and throws? It would be a ReferenceError, caught by catch, onNavigate never called!
Let me check how__basePath is defined.
- Assistant
Let me try running vitest with simpler options to avoid the hang.
- Assistant
Let me try using the workspace node_modules properly.
- Assistant
The React mock didn't work because Link imports its own React. Let me check how the bundle is structured and try a different approach.
- Assistant
Uses jsx runtime. Let me mock that.
- Assistant
Let me try running vitest programmatically with a minimal config.
- Assistant
Tests work with a simplified config. I'll add a temporary harness covering Next.js's onNavigate cases.
- Assistant
Need to put the file in the repo so node can find vitest.
- Assistant
It's picking up the vite.config.ts with projects. I need to disable config file.
- Assistant
The capture isn't working well. Let me copy the exact mock technique from the existing link-navigation test.
- Assistant
I'll adapt the existing test counters infrastructure - the download test imports from
link.js, not tsx. - Assistant
Let me create a temp test file based on the same patterns and run it with startVitest config false.
- Assistant
Confirmed external+replace is broken. Checking whether hybrid app/pages fixtures or client navigation have other gaps.
- Assistant
Checking applyLocaleToHref for absolute URLs and the correct replace target.
- Assistant
Implementing the missing external-link
replacehandling to match Next.js. - Assistant
Checking hybrid app/pages apps: whether app navigation chmod steals pages-router Link clicks.
- Assistant
Trying to reproduce with a minimal fixture and vinext's build/start — checking how to spin one up quickly.
- Assistant
Checking how Next.js merges props onto the anchor — order matters.
- Assistant
Unit tests import from
dist/shims_u/link.js, so I need to rebuild and re-verify. - Assistant
I'll fix the spread order so handlers override rest props, and strip Link-only props like Next.js.
- Assistant
There's an extra
});— fixing that. - Assistant
I dropped the
LinkStatusContext.Providerclose — fixing it. - Assistant
I'll check type declarations and simplify prop stripping.
- Assistant
I'll move shallow/legacyBehavior/transitionTypes into the main destructure for cleaner code.
- Assistant
There's a typo in the comment — fixing that and updating the destructure.
- Assistant
Now update the component destructuring to extract shallow, legacyB ehavior, transitionTypes,passHref.
- Assistant
Let me update the destructure and simplify the later props stripping.
- Assistant
Now remove the old stripping code that's redundant.
- Assistant
There's still the old stripping block. Let me remove اخیر it.
- Assistant
Remove lines 654-666.
- Assistant
Note: unused vars
_passHrefetc. might trip lint. Using underscore prefix should usually be OK for unused. - Assistant
All 7 pass. Running existing link-navigation tests next.
- Assistant
All existing tests pass. Cleaning up temp files and reviewing the final diff.
- Assistant
Tightening onNavigate so URL parse errors can't swallow the callback (which would make it look like it never fired).
- Assistant
I may have removed the absoluteHref resolution — checking.
- Assistant
Restoring the missing
absoluteHref/absoluteFullHrefdefinitions. - Assistant
Good. running the tests once more.
- Assistant
All tests pass. Final review of the change:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.