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, then look at the Next.js reference implementation for
onNavigate.Assistant
I need to make only one tool call per response. Let me find the Link shim files.
Assistant
The
onNavigateappears to already be partially implemented. Let me look at the Next.js reference implementation and the test file to understand what's expected.Assistant
The test file doesn't exist yet. Let me look at the Next.js reference implementation.
Assistant
No nextjs-ref directory. Let me check the full link.tsx file - particularly the middle truncated section, to understand what the current state is. Let me open it.
Assistant
The
onNavigateappears to be implemented. Let me look at the full click handler section and the surrounding code that was truncated.Assistant
The
onNavigateappears already implemented. Let me check git history to understand the current state and run the relevant tests.Assistant
Let me look at the existing tests for onNavigate to understand the expected behavior.
Assistant
Let me look at the e2e tests and fixtures for onNavigate to understand the actual expected behavior.
Assistant
Let me look at the fixtures and run the existing unit tests to see the current state.
Assistant
Let me run the existing unit tests to see if they pass.
Assistant
Vitest is taking too long. Maybe it's running the whole suite. Let me try with a filter. Actually
npx vitest run tests/link-navigation.test.tsshould run that file. Maybe it's slow to start. Let me try with a longer timeout, or maybe use the vp test command. Let me check vitest config.Assistant
Vitest hangs - maybe it needs a server. Let me check the vitest config.
Assistant
Let me run a specific test by name with the unit project filter.
Assistant
It's trying to install vitest via npx. Let me use the project's vitest directly.
Assistant
The test runner works. Let me run the full link-navigation test suite.
Assistant
All unit tests pass. The onNavigate appears implemented. Let me look more carefully at the Next.js reference and the actual contract. Let me search for any reference docs and examine the full handleClick once more.
Assistant
Let me examine the Next.js reference implementation of onNavigate in detail.
Assistant
Let me check the Next.js version installed and look at the link.d.ts for the OnNavigateEventHandler signature.
Assistant
Let me check the compiled dist version of the link shim, since e2e tests may run against the built dist.
Assistant
The implementation is present in both source and dist. Let me look at the existing link-navigation tests to see if there's a test for onNavigate firing on a normal click, and write a reproduction.
Assistant
Let me check what
navigateClientSidedoes and how it calls the runtimenavigatefunction.Assistant
Let me check git status to see if there are uncommitted changes.
Assistant
Working tree clean, yet onNavigate appears implemented. Let me run the actual e2e tests to see if there's a runtime bug. Let me check the playwright setup.
Assistant
Running full e2e would be expensive. Let me search for any copy of the Next.js e2e link-on-navigate test in the repo, and check how the
next/linkshim is resolved at runtime (src vs dist).Assistant
Let me look at the
renderIsolatedLinkhelper to write a focused reproduction test.Assistant
Let me write a temporary reproduction test to verify the onNavigate behavior in the App Router path.
Assistant
My mock is incomplete. Let me reuse the existing test helpers. Let me look at the shared helpers.
Assistant
I need to mock jsx-runtime too. Let me rewrite the temp test to mirror the existing
renderIsolatedLinkhelper exactly.Assistant
The jsx-dev-runtime issue is from stubbing NODE_ENV=production. Let me remove that stub.
Assistant
The unit-level reproduction passes — onNavigate fires correctly. The source already implements it. Let me check how
next/linkis resolved at runtime in the app router, to ensure the e2e uses this same shim.Assistant
The app router uses the built dist
link.jsat runtime (which also has onNavigate). Let me run the actual e2e onNavigate tests to definitively determine the state. Let me check playwright browsers availability.Assistant
No playwright browsers installed in ~/.cache/ms-playwright. Let me check elsewhere. Actually the directory listing was empty. Let me check if chromium is installed.
Assistant
No browsers available; installing would be too slow. Let me reconsider. Let me check git history for when onNavigate was added to the link shim.
Assistant
onNavigate was added in the initial release and refined later. Let me look at what the recent refactor (#1322) changed in link.tsx, since it might have introduced a runtime bug.
Assistant
Let me check for a system Chrome/Chromium that playwright could use, and look at how the app-router e2e onNavigate fixture page is set up.
Assistant
There's a system google-chrome. Let me try running the onNavigate e2e test. First, let me see the full playwright config for browser launch options.
Assistant
The default needs bundled chromium. Let me try installing it (network may be available).
Assistant
Chromium installed. Now let me run the onNavigate e2e test in the app-router project.
Assistant
The app-router onNavigate e2e test passes. Let me run the pages-router onNavigate e2e test.
Assistant
Both onNavigate e2e tests pass. The implementation works. The issue references the Next.js e2e test
test/e2e/link-on-navigate-prop/index.test.tswhich doesn't exist in vinext. Let me search the whole filesystem for that test or its fixture.Assistant
No trace of the Next.js e2e test. Let me examine the Next.js onNavigate contract more deeply, including the pages-router link and any transitionTypes interaction.
Assistant
Let me look at the link-status example and the Next.js useLinkStatus implementation to understand the "click state tracking" aspect.
Assistant
Let me look at the Next.js links.js for how the link status is set during navigation. The
setOptimisticLinkStatus(PENDING_LINK_STATUS)is called when a navigation happens via the link instance. Let me read links.js around line 69-180.Assistant
Let me look at how Next.js Link provides LinkStatusContext and sets up the link instance.
Assistant
Let me search more broadly for onNavigate usage patterns and View Transitions interactions in the repo and Next.js package.
Assistant
Let me verify the built dist link.js handleClick is complete and matches the source (in case dist is stale).
Assistant
The dist matches source. Let me check whether there's any e2e test exercising
useLinkStatuspending state, and look at the link-status example setup.Assistant
Let me look at the app-router-playground example for onNavigate/ViewTransition usage, which may be the target.
Assistant
The
TransitionLinkexample relies on onNavigate + preventDefault + router.push. The basic onNavigate e2e passes. Let me now test the two untested behaviors —useLinkStatuspending state andreplace+onNavigate — in a real browser. Let me create a temporary fixture page and spec.Assistant
Let me create a temporary fixture page testing useLinkStatus pending + onNavigate + replace.
Assistant
Let me run with the file path positioned correctly like the earlier working command.
Assistant
Both tests failed. Let me see the full output including the first test's failure and any console errors.
Assistant
The page loaded and
useLinkStatusidle works. Let me rewrite the test to check the window flags robustly after navigation (the source#firedgets replaced).Assistant
Critical finding:
FIRED: null— onNavigate did NOT fire for the cross-route href, yet navigation to the target happened. But it DID fire for?page=2. Let me instrument with anonClickflag to determine whether vinext's click handler runs at all.Assistant
click: nullandpendingLog: []— the page isn't hydrating client-side at all (no onClick, no useEffect). The difference: relative-query is a client component imported by a server page, while mine is a"use client"page. Let me restructure to mirror the working relative-query pattern (server page importing a client component).Assistant
Still not hydrating. Let me isolate: remove
useLinkStatus(it may not be exported at runtime, breaking the client module). Test plain onNavigate + onClick for cross-route href.Assistant
HYDR0: null— the page isn't hydrating at all. The dev server is being reused from earlier runs (before this route existed), so it has stale state. Let me kill any running dev server and re-run fresh.Assistant
Those are defunct (zombie) processes, the actual dev server is killed. Let me re-run the test fresh (it'll start a new dev server). But to force a fresh server, I need
reuseExistingServerto be false. Since I'm not in CI, it reuses if a server is on the port. I killed it. So a new one will start. But the new server might also be reused if a leftover is on 4174. Let me ensure port 4174 is free.Let me set CI=1 to force reuseExistingServer=false? Actually CI=1 changes other things (reporter). Let me just ensure port is free and re-run. The server will start fresh and scan the new route.
Actually, the defunct processes are zombies (parent died). They don't hold the port. Let me verify port 4174 is free.
Assistant
Still not hydrating even with a fresh server. Let me check the dev server logs for compilation errors on this route, and check the actual rendered HTML.
Assistant
Let me start the dev server manually and inspect the rendered HTML and hydration state directly.
Assistant
The HTML renders fine with the SPA runtime. My test clicks before hydration completes — the relative-query test uses
waitForAppRouterHydration. Let me check that helper and wait for hydration.Assistant
My test was clicking before hydration — a test bug, not a vinext bug. Let me rewrite the test to wait for hydration, then re-test all behaviors including
useLinkStatuspending and preventDefault.Assistant
The helpers import path is wrong. The spec is at
tests/e2e/app-router/nextjs-compat/_tmp_onnav_status.spec.ts. The helpers is attests/e2e/helpers.ts. Fromnextjs-compat/subdir, the path to helpers is../../helpers. Let me check the existing navigation.spec.ts import.Assistant
waitForAppRouterHydrationtimes out on my page. The manually-started dev server may be stale. Let me kill all dev servers and run fresh with CI=1, and add a sanity check that the existing nav-link-test page hydrates.Assistant
With a fresh server, both hydrate. The earlier failures were a stale dev server. Now let me run the full onNavigate + pending + prevent tests with useLinkStatus, fresh server.
Assistant
All three core behaviors work in the real app router: onNavigate fires (
FIRED: true), useLinkStatus pending toggles (["idle","pending"]), and preventDefault cancels navigation. Let me now verify the TransitionLink pattern (preventDefault +router.push) which is the actual Next.js fixture pattern, plusreplace.Assistant
Key finding: the TransitionLink pattern (preventDefault + router.push) leaves
useLinkStatuspending idle (["idle"]). Let me verify this matches Next.js behavior — in Next.js,router.pushdoesn't carry the link instance, so pending wouldn't toggle either. Let me confirm onNavigate is in the committed HEAD.Assistant
Confirmed: Next.js
router.pushpassesnulllink instance, so pending stays idle — vinext matches. The implementation is faithful. Let me do a final broad search for any cached copy of the Next.js link-on-navigate e2e test or its fixture anywhere on the system.Assistant
No cached copy exists. Let me do a definitive fresh check of the on-disk source file's onNavigate implementation to be 100% sure it's present and correct.
Assistant
The onNavigate implementation is fully present and correct on disk and in dist. I've verified via real-browser e2e that all three issue failure modes are actually resolved in the current repo: onNavigate fires,
useLinkStatuspending toggles (matching Next.js semantics), preventDefault cancels, and replace works — in both app and pages routers.This indicates the repo already contains the fix. Let me clean up all my temporary test files/fixtures and verify the existing onNavigate test suites pass.
Assistant
Working tree clean. Now let me run the existing onNavigate-related unit tests to confirm they pass.
Assistant
Unit tests pass. Now let me run the e2e onNavigate tests for both routers to confirm green.
Assistant
All onNavigate tests pass across unit and e2e (app + pages routers). The implementation is complete and faithful to Next.js 16.2.6's contract. Let me run the remaining link unit test to be thorough, then do a final clean check.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.