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 callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /vinext, current file: none) bash-$
Assistant
I'll start by exploring the repository structure to understand the codebase.
Assistant
Let me look at the full file and the failing test suite.
Assistant
No test file found. Let me search more broadly.
Assistant
The test file doesn't exist in this repo yet. Let me look at the Next.js reference implementation to understand the
onNavigateAPI contract.Assistant
Let me check the Next.js node_modules for the
onNavigateimplementation.Assistant
Let me look at the Next.js type definitions for
onNavigateto understand the full contract.Assistant
Let me look at the full link.tsx file, particularly the props destructuring part that was truncated.
Assistant
Let me check the git status to see the current state of changes.
Assistant
The working tree is clean, meaning the
onNavigatecode already exists. Let me examine the existing tests that referenceonNavigateto understand what's expected.Assistant
There's already an
onNavigatetest. Let me look at the fixture component and the Next.js test suite forlink-on-navigate-prop.Assistant
Let me look at the Next.js test suite for
link-on-navigate-prop. Let me search the whole filesystem for this test.Assistant
No such test file exists in the filesystem. The issue references a Next.js test that runs against vinext. Let me look at the pages-router link-advanced test that also references onNavigate.
Assistant
Let me look at the existing unit tests for the link to understand the test setup.
Assistant
Let me search for
onNavigatein the unit tests and shims test.Assistant
Let me run the existing tests to see the current state.
Assistant
Let me check the dist version of the link shim and compare.
Assistant
Let me check the git history of the link.tsx file to see when onNavigate was added.
Assistant
The
onNavigatewas added in commit cb2d1c9. Let me check hownext/linkis resolved and whether there's an App Router-specific link that might not haveonNavigate.Assistant
Let me look at the existing onNavigate test in link-navigation.test.ts and the test harness.
Assistant
Let me search for all references to the Next.js test path in the repo.
Assistant
Let me look at the full onNavigate test block and surrounding context.
Assistant
Let me search the whole filesystem for the Next.js test or any app fixture related to on-navigate.
Assistant
Let me look at the full handleClick implementation with line numbers to carefully analyze it.
Assistant
Let me look at the App Router link (app-dir/link.d.ts) — there might be a separate App Router Link implementation.
Assistant
Let me look at the App Router's link.js to understand its
onNavigatebehavior.Assistant
The contract matches Next.js. Let me verify how
next/linkresolves to the shim in the build. Let me check the plugin's module resolution.Assistant
Let me verify the onNavigate commit is actually in the current HEAD's history.
Assistant
Let me look at the dist version's onNavigate implementation to confirm the built artifact works.
Assistant
Both src and dist have the implementation. Let me actually run the existing e2e tests for onNavigate to see if they pass. Let me check the test infrastructure first.
Assistant
The implementation appears to exist in both src and dist. Let me actually run the existing onNavigate e2e test to see if it passes or fails. Let me build first.
Assistant
Build succeeded. Now let me run the specific onNavigate e2e test.
Assistant
Let me install the Playwright browser and also look for any Next.js test references in the repo.
Assistant
Let me look at how the deploy suite runs Next.js tests against vinext.
Assistant
Let me check the e2e-deploy script and search for any cached Next.js checkout.
Assistant
No cached Next.js checkout. Let me look at the e2e-deploy.sh to understand how vinext deploys the Next.js test app. This is important to understand how
next/linkresolves.Assistant
Let me open the actual link.tsx file to carefully verify the current state of the onNavigate implementation.
Assistant
Let me look at the vinext view-transitions example that uses onNavigate to understand the expected API.
Assistant
The implementation looks correct. Let me install the Playwright browser and run the actual e2e test to see the real behavior.
Assistant
The basic onNavigate test passes. The fix (cb2d1c9, Mar 12) predates the CI run (May 20), so there's a REMAINING bug. Let me find the actual Next.js test to understand the failing scenarios. Let me try to fetch it from GitHub.
Assistant
I can access GitHub. Let me fetch the full test and the test app.
Assistant
Now I have the actual test. Let me fetch the test app files to understand the structure.
Assistant
Let me fetch the app-router and pages-router page structures.
Assistant
I now have the full Next.js test and app. Let me analyze. The key scenarios involve external links with
replace, modifier keys, download, target="_blank", and internal navigation with state tracking via a shared layout. Let me set up a temporary reproduction in the app-basic fixture. First, let me understand the app-basic fixture structure.Assistant
Let me create a temporary reproduction fixture mirroring the Next.js test app. Let me first check if app-basic has a pages directory and how existing nextjs-compat fixtures are structured.
Assistant
Now let me create a temporary reproduction fixture mirroring the Next.js test app (App Router version). I'll add it under the app-basic fixture.
Assistant
Now let me create a temporary spec to reproduce the Next.js test scenarios against the app-basic dev server.
Assistant
Now let me run the temporary reproduction spec against the app-router dev server.
Assistant
There's an issue with the helpers.ts import. It seems the spec file is being treated as ESM but helpers.ts uses CommonJS exports. Let me look at how the existing navigation.spec.ts imports the helper and check the helpers.ts file. Actually the existing spec imports
from "../../helpers"and works. Let me check what's different. Maybe it's a TypeScript/ESM issue with how I named the file or the import.Wait, the error "exports is not defined in ES module scope" at helpers.ts:3. Line 3 is just a comment
*. Hmm, that's odd. Actually the error points to helpers.ts line 3 char 23 which is in a comment block. That suggests the helpers.ts file might haveexportssomewhere and is being loaded as ESM. But the existing navigation.spec.ts imports it fine.Actually, maybe the issue is that my spec file location or naming causes it to be picked up by a DIFFERENT project config that compiles differently. Wait, "No tests found" after the error.
Actually the real issue: the error happened during loading helpers.ts. But the existing navigation.spec.ts uses the same import. Let me check helpers.ts.
Assistant
Let me rewrite the spec without the helper import (which is causing a load error) and use a simple content-based wait.
Assistant
Let me use
--grepto filter to my repro tests.Assistant
All tests fail — even the button click (toggle-lock) doesn't update state. This suggests the page isn't hydrated when I click. I removed the hydration helper. Let me check what
waitForAppRouterHydrationdoes.Assistant
The helper is at
tests/e2e/helpers.ts. Let me fix the import path and use the hydration helper.Assistant
Let me view and fix the ready function using the editor.
Assistant
The substitution mangled the template literal. Let me recreate the file cleanly using the create command.
Assistant
With proper hydration, 6 of 7 App Router tests pass — only the external-link-with-
replacetest fails. Now let me check the Pages Router version, which may have more failures. Let me fetch the pages-router test app files.Assistant
Let me look at the pages-basic fixture structure to set up the Pages Router reproduction.
Assistant
6 of 7 App Router tests pass in dev mode — only external+replace fails. But the deploy suite uses a production build. Let me test in production mode to see if more tests fail there. Let me check the app-basic build/start commands.
Assistant
Let me build app-basic in production mode and test against it. First, let me parametrize the spec's BASE via env.
Assistant
vinext build --prerender-allis the right command. Let me build app-basic in production mode.Assistant
Production server is running on 4184. Let me run the repro spec against it (the app-router project will still start the dev server, but my spec will hit the prod server via ONNAV_BASE).
Assistant
Only the external-link-with-
replacetest fails in both dev and production. This is the "history state replacement" failure. Let me look at the full Link component to understand the href variables before fixing.Assistant
Only external+replace fails in the App Router (both dev and prod). The issue mentions 8 failures, so the Pages Router may have more. Let me set up a Pages Router reproduction. First, let me check the pages-basic vite config setup.
Assistant
Let me set up the Pages Router reproduction. I'll create a shared OnNavigate component and conditionally wrap it in
_appfor the test routes (reversible). First the component and pages.Assistant
Now let me modify
_app.tsxto conditionally wrap with OnNavigatePages for the test routes. Let me back it up first.Assistant
Now let me create the Pages Router repro spec.
Assistant
Both routers confirm: only the external-link-with-
replacetest fails. This is the "history state replacement" bug. Now let me implement the fix in the link shim. Let me view the exact code to edit.Assistant
Now let me implement the fix — handle
replacefor truly external links by replacing history state, mirroring Next.js.Assistant
Now let me check whether the dev server uses the src or dist version of the shim, so I know what to rebuild.
Assistant
Both dev and prod use the dist shim, so I must rebuild vinext. Let me rebuild.
Assistant
The dist has the fix. Now I need to rebuild app-basic (which bundles the shim) and restart servers. Let me kill running servers and rebuild.
Assistant
Now let me re-run the App Router repro against the rebuilt production server.
Assistant
All tests now fail at hydration — the production server may not be serving the rebuilt bundle correctly. Let me check the server log and the page.
Assistant
The server on 4184 is stale (referencing deleted old asset hashes). Let me check what's actually running and restart cleanly.
Assistant
This is a build artifact caching issue unrelated to my fix. Let me verify via the dev server instead. Let me kill all servers, clear Vite cache, and run the dev repro (which uses the rebuilt dist shim).
Assistant
All 7 App Router tests pass now (including external+replace). Let me run the Pages Router repro to confirm the fix works there too.
Assistant
All 7 Pages Router tests pass too. Now let me verify I didn't break existing tests. Let me run the existing onNavigate e2e tests (navigation.spec.ts and link-advanced.spec.ts).
Assistant
Existing onNavigate tests pass. Let me run the broader link test suites to ensure nothing broke. Let me run the full link-advanced spec (Pages) and the full navigation spec (App).
Assistant
All link-advanced tests pass. Now let me run the unit tests for onNavigate to ensure they still pass.
Assistant
The unit tests are slow to start. Let me check the vitest config and try running with the
vprunner.Assistant
The onNavigate unit tests pass. Let me run the link-navigation unit tests (which include the onNavigate download-link test).
Assistant
All 25 link-navigation unit tests pass. Let me verify
applyLocaleToHrefdoesn't mangle external URLs (edge case for thelocation.replace(fullHref)path).Assistant
applyLocaleToHrefpreserves external URLs. Now let me verify the fix works in a production build too (the deploy suite uses production). Let me do a clean rebuild of app-basic.Assistant
The browser-specific project doesn't match my spec (it matches
.browser.spec.ts). Let me run with the app-router project (which starts dev server at 4174, but my spec hits 4184 prod). The app-router project will start the dev server unnecessarily, but that's fine. Let me run just the "external link with replace" test against prod.Assistant
The fix works in production too. Now let me clean up all temporary reproduction files. Let me check git status to see everything I added/modified.
Assistant
Let me clean up all temporary files and restore
_app.tsx.Assistant
Only my
link.tsxsource change remains. Let me verify the dist is tracked/gitignored and check the final diff.Assistant
The dist is gitignored, so only the src change is submitted. Now let me make sure I didn't break other Link behaviors. Let me search for existing tests that exercise external links or
replaceon<Link>.Assistant
Let me check
routing-misc.spec.tswhich references external links, to ensure my change doesn't break external link handling.Assistant
That test is server-side, unaffected. Let me run the full app-router nextjs-compat navigation spec to confirm no regressions.
Assistant
All navigation tests pass. Let me verify how non-http schemes (mailto:, tel:) are handled, to ensure my external-link change doesn't affect them.
Assistant
mailto:/tel:are treated as external (not dangerous) and only myreplacebranch is new — non-replace external links are unchanged. Let me run the existing native-URI-scheme click test to be safe.Assistant
Let me see the full error for this test.
Assistant
This is a test-isolation artifact (mock setup order with
-tfilter), not my change. Let me confirm by re-running the full file.Assistant
All 25 pass when running the full file. The
-tfailure was a test-isolation artifact. Let me do a final check of the repo state and confirm the dist is in sync with my source.Assistant
Everything is clean and in sync. Let me do a final review of the complete change in context.
Assistant
The fix is complete and well-placed. Let me do a final verification of the complete diff to be submitted.
Assistant
The diff is clean and minimal. Let me kill any lingering servers before submitting.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →