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 understanding the codebase.
Assistant
Let me look at the full file and the test suite to understand what's expected.
Assistant
I need to make single tool calls. Let me look at the test suite.
Assistant
The test suite mentioned in the issue is
test/e2e/link-on-navigate-prop/index.test.ts. Let me search for it.Assistant
The
onNavigateprop is already implemented. Let me look at the Next.js reference implementation to understand the exact API contract and find what's missing.Assistant
The onNavigate is already implemented. Let me look at the existing tests to understand what might be broken, and run them.
Assistant
Let me look at the e2e tests that test onNavigate behavior.
Assistant
The onNavigate is already implemented. Let me check the git history and status to understand the current state.
Assistant
Let me look at the Link component props destructuring carefully.
Assistant
The test suite mentioned doesn't exist in this repo - it's from the external Next.js Deploy Suite. Let me find the Next.js reference implementation.
Assistant
Interesting. So in this version of Next.js (the installed one), the
onNavigatecallback receives{ preventDefault: () => ... }- nourlproperty! Let me check the installed Next.js version.Wait, the issue mentions Next.js v16.2.6. The installed one might be a different version. Let me check.
Assistant
Key finding: Next.js 16.2.6's
onNavigatecallback signature is(event: { preventDefault: () => void }) => void— nourlproperty. Let me look at the full Next.js link implementation and the useLinkStatus implementation.Assistant
So in Next.js 16,
useLinkStatususesuseOptimisticwith aLinkStatusContext. Let me look at how the Link sets the pending state. In Next.js, the Link usesuseOptimisticto getlinkStatus, and the navigation dispatch sets the optimistic pending state viasetLinkForCurrentNavigation.Let me look at the full Link component in Next.js to understand the useLinkStatus implementation.
Assistant
Let me check how
next/linkis wired up and whether there are other Link implementations.Assistant
Let me run the existing unit tests related to link navigation and onNavigate.
Assistant
Interesting — the test mentions "Ported from Next.js: test/e2e/link-on-navigate-prop/index.test.ts". So vinext has ported some of these tests into the unit test suite. Let me look at the broader context of link-navigation.test.ts to find all onNavigate related tests.
Assistant
Only one test in link-navigation.test.ts references onNavigate (the download test). Let me run that whole file's link navigation tests to confirm they pass. But the real issue is the e2e suite. Let me first run the existing unit tests to make sure nothing is broken.
Let me actually focus on the real task. The issue says onNavigate is "not implemented" but it clearly is in the code. The likely scenario: the implementation has a subtle bug that makes the onNavigate tests fail. Let me look at the actual Next.js test file
test/e2e/link-on-navigate-prop/index.test.tsto understand what it tests. Since it's referenced, maybe I can find it referenced in the codebase with ported tests.Let me search for "link-on-navigate-prop" across the whole repo.
Assistant
Let me run the link-navigation unit tests to see the current state.
Assistant
The unit tests are slow. Let me search for the actual Next.js test file content, which might be cached or referenced somewhere.
Assistant
Let me check the git history of the link.tsx file to understand when onNavigate was added.
Assistant
So onNavigate has been there for a while. Let me look at the existing pages-router link-advanced spec and the full set of onNavigate tests.
Assistant
Let me look at the nextjs-compat tests and fixtures to understand the full scope of onNavigate testing.
Assistant
Let me look at the dist build to verify the source matches, and check if there's any transform that processes Link props.
Assistant
Let me look at the playwright config and how the e2e fixtures are served.
Assistant
Let me check what Next.js exports from
next/linkand whether vinext exports the same.Assistant
Let me look at the
renderIsolatedLinkhelper to write a quick reproduction.Assistant
Let me look at the top of the link-navigation.test.ts to understand the helpers like
mockReactAnchorCaptureForLinkOnly_DO_NOT_REUSEandcreateTestNavigationRuntime.Assistant
Let me write a temporary reproduction test to verify onNavigate fires on a normal click.
Assistant
The vitest run is timing out. Let me check the test runner setup.
Assistant
The test runner is
vite-plus(vp). Let me try the proper runner with a longer timeout and stream output.Assistant
The existing mock approach is tricky. Let me verify the production shim path and check whether the built dist matches the source.
Assistant
shimsDir = path.resolve(__dirname, "shims")where__dirnameispackages/vinext/dist(built) orpackages/vinext/src(source). Since the package is built (postinstall: vp run vinext#build),__dirnamewould bedist. So in production,next/link→dist/shims/link.js. Let me check the dist version has onNavigate.Assistant
The dist has onNavigate. Let me check the most recent commit that touched link.tsx for possible regressions.
Assistant
Let me check the .agents directory and any issue analysis notes that might have more detail.
Assistant
The deploy suite checks out the real Next.js repo at v16.2.6 and runs its tests against vinext. I need the actual Next.js test content. Let me look at the run script.
Assistant
Let me search the whole filesystem for a next.js checkout that contains the test file.
Assistant
I need the actual Next.js test file content. Let me check if there's network access to fetch it.
Assistant
I have network access. Let me get the full test file and the fixture.
Assistant
Excellent! I have the actual test. Now let me download the fixture files to understand the exact link configurations.
Assistant
Now let me download the app-router and pages-router page files to understand the structure.
Assistant
I have the full test and fixture now. Let me fix my reproduction by also mocking jsx-dev-runtime (which Vite uses in dev mode).
Assistant
My unit test confirms onNavigate DOES fire on internal clicks. The external+replace case does NOT call preventDefault/location.replace (Test 7 failure). But the issue claims ~8 failures, so there may be more. Let me reproduce the FULL Next.js fixture in vinext to find all failures definitively. Let me examine the test fixtures structure.
Assistant
Let me look at the deploy script to understand how the app is built/served in the deploy suite.
Assistant
Let me look at the actual dist click handler to ensure onNavigate is fully present in the production build.
Assistant
My analysis shows the only clear failure is Test 7 (external link with
replace). Let me look at the full handleClick context to understandnormalizedHrefandresolvedHreffor external links.Assistant
I now understand the fix needed for Test 7. Let me check how Next.js computes the
hrefused forlocation.replace(formattedHref) to match exactly.Assistant
Let me check
withBasePathand related utils to determine the correct href forlocation.replace.Assistant
My analysis confirms the fix needed for Test 7 (external link with
replace). But the issue claims ~8 failures and "onNavigate never fires". To be definitive, let me reproduce the full behavior in vinext's e2e setup. Let me look at an existing app-basic fixture page for conventions.Assistant
Let me make the fix for the external link with
replacecase (Test 7). First, let me open the file at the relevant lines.Assistant
Let me use the
replacecommand to make the edit.Assistant
The
<<<was wrong. I need>>> REPLACEnot<<<. Let me redo with proper markers.Assistant
The fix is applied. Now let me set up a full e2e reproduction mirroring the Next.js fixture to verify all tests pass for both routers. Let me check pages-basic's _app.tsx first.
Assistant
The fix is applied. Now let me set up a full e2e reproduction mirroring the Next.js fixture to verify all behaviors. Let me create the App Router fixture (layout + page + subpage) and Pages Router fixture.
Assistant
Now let me create the Pages Router fixture with window-backed state (to persist across navigation without modifying the global
_app).Assistant
The subpage import path is wrong. Let me fix it.
Assistant
Now let me write the playwright spec mirroring the Next.js test.
Assistant
Now let me run the App Router spec to verify the fix works. This will start the dev server automatically.
Assistant
Playwright browsers aren't installed. Let me install chromium.
Assistant
Now let me check the playwright config's default browser settings.
Assistant
Let me run the App Router spec now.
Assistant
All 6 App Router tests pass with the fix! This confirms onNavigate fires, preventDefault works, and the external+replace history fix works. Now let me run the Pages Router spec (which rebuilds vinext dist).
Assistant
All 6 Pages Router tests pass too. Let me rigorously confirm the fix is what resolved the replace test by temporarily reverting it and running just that test.
Assistant
Confirmed: without the fix, the replace test FAILS (history.length 2→3, a push instead of replace) — exactly the "History state replacement not working" failure. Now let me re-apply the fix.
Assistant
Fix re-applied. Now I need to rebuild the dist so the production deploy suite uses the fix, then run existing tests for regressions, and finally clean up the temporary test/fixture files I added (since the system prohibits adding new tests). Let me rebuild dist.
Assistant
Dist is rebuilt with the fix. Now let me run the existing link unit tests to ensure no regression.
Assistant
All 25 link-navigation unit tests pass. Let me run the existing onNavigate e2e tests to confirm no regression (app-router navigation.spec.ts and pages-router link-advanced.spec.ts).
Assistant
Both existing onNavigate e2e tests pass with no regression. Now let me clean up all the temporary test/fixture files I added (the system prohibits adding new tests), and check git status.
Assistant
Only
packages/vinext/src/shims/link.tsxis modified (dist is gitignored, and the deploy suite rebuilds from source). Let me review the final diff.Assistant
The diff is clean and minimal. But the deploy suite uses a production build (
vinext build+vinext start), while my e2e used dev mode. The issue's "~8 failures" + "onNavigate never fires" claim suggests onNavigate might not fire in prod. Let me verify the production build path. Let me check the app-basic fixture's build setup.Assistant
Let me check the deploy script's build/start commands to test the production path.
Assistant
Let me recreate the App Router fixture and test the production build path (build + start), which is what the deploy suite uses.
Assistant
Build succeeded. Let me verify onNavigate is in the production bundle.
Assistant
onNavigate is in the production client bundle. Let me verify the full click handler (including the replace fix) is in the client bundle.
Assistant
Let me confirm
onNavigateis actually invoked (not just referenced) in the production client bundle.Assistant
The production bundle contains the
onNavigateblock and thelocation.replacefix. Let me run the production server and verify onNavigate fires end-to-end in prod.Assistant
The
vpCLI doesn't have astartcommand — it haspreviewfor production. But the deploy script usesvinext buildandvinext start(thevinextbinary, notvp). Let me check thevinextbinary. The deploy script usesrun_pnpm exec vinext buildandvinext start. So there's avinextCLI. Let me find it.Assistant
The prod server is running. Let me write a temporary playwright config + spec to test onNavigate firing and replace in production.
Assistant
The /tmp config can't resolve modules. Let me put the temp config/spec inside the repo.
Assistant
Both production tests pass — confirming onNavigate fires in prod (deploy suite's mode) and my replace fix works in prod. Let me stop the server and clean up all temporary files.
Assistant
Only
link.tsxis modified (dist is gitignored; the deploy suite rebuilds from source). Let me run the shims.test.ts onNavigate unit tests to confirm no regression.Assistant
All 5 onNavigate shims tests pass. Let me do a final review of the complete change.
Assistant
The change is clean — only
link.tsxmodified, no untracked files. Let me verify the vinext dist is gitignored (so the deploy suite rebuilds from the fixed source).Assistant
dist/is gitignored, and the deploy suite rebuilds from source (viavp run vinext#buildand postinstall), so the source fix ships correctly. Let me do a final verification that the on-disk vinext dist also reflects the fix (in case the working tree is used directly).
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.