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 to understand the codebase and locate the relevant files. Let's first get an overview.
- Assistant
Let me explore the repository structure more to understand the project.
- Assistant
Let me explore the packages directory, especially the Link component implementation.
- Assistant
Let me look at the Link component implementation and the failing tests.
- Assistant
Let me see the full file and understand the current
onNavigateimplementation better. - Assistant
Let me look at the test file to understand what the tests expect.
- Assistant
Let me search more broadly for test files related to onNavigate.
- Assistant
Let me look at the test mentioned in the issue:
test/e2e/link-on-navigate-prop/index.test.ts - Assistant
The test files might be in a different location. Let me search more broadly.
- Assistant
Let me look for e2e tests related to Link component.
- Assistant
Let me look at these test files to understand what they expect.
- Assistant
Let me try again with the correct syntax.
- Assistant
Let me look at the other test file and the .nextjs-ref directory to understand the Next.js implementation.
- Assistant
Now let me look at the Next.js reference implementation to understand how
onNavigateis supposed to work. - Assistant
Let me check if there's a .nextjs-ref directory.
- Assistant
Let me look at the test examples in the repository to understand what's expected. The issue says the tests are in
test/e2e/link-on-navigate-prop/index.test.tsbut let me look for the e2e test fixtures/pages used by the tests. - Assistant
Let me look for the link test pages.
- Assistant
Let me examine the test fixtures and the link component to understand the issue better.
- Assistant
Now let me check the relative query link component:
- Assistant
Let me look at the pages-router link-test fixture to understand the link-relative-query test.
- Assistant
Let me check the fixtures directory for pages router test apps.
- Assistant
Let me examine the pages router link-test fixture to understand the onNavigate test case.
- Assistant
Now let me understand the issue better. The
onNavigateprop exists in the Link component but it seems like there might be issues with how it fires, what URL it reports, or how the event is constructed. Let me look at the actual Next.js reference implementation to understand the expected behavior. - Assistant
Let me look at the Next.js implementation to understand the
onNavigateAPI contract. - Assistant
Let me read the Next.js reference link implementation.
- Assistant
Now let me see the actual implementation of the
linkClickedfunction in Next.js to understand howonNavigateworks. - Assistant
Let me look at the full Next.js 16 implementation of onNavigate to understand the expected API contract:
- Assistant
Now let me look at the actual
onNavigatetype definition in Next.js to see what properties the event has: - Assistant
Let me find the OnNavigateEventHandler type definition.
- Assistant
Let me look at the type definitions to understand the expected API.
- Assistant
Let me look at the full
handleClickfunction in the link.tsx to understand the current implementation: - Assistant
Let me look at the full handleClick implementation and surrounding code.
- Assistant
Let me search for the test file mentioned in the issue:
- Assistant
Let me look at those test files to understand the test expectations.
- Assistant
Let me look at the shims.test.ts for onNavigate tests:
- Assistant
Let me look at the onNavigate tests in more detail:
- Assistant
Let me look at the link-navigation.test.ts file for onNavigate tests:
- Assistant
Let me now look for the full link-navigation test file to understand the test suite structure and find the relevant onNavigate tests.
- Assistant
Let me understand the full picture - let me check the AGENTS.md for context about the project:
- Assistant
Let me run the existing tests to understand what's failing:
- Assistant
Let me try a more focused test run:
- Assistant
Let me try running the tests with a timeout limit:
- Assistant
Let me try running the tests differently:
- Assistant
Let me check how tests are run in this project:
- Assistant
Let me try a different approach - let me just look at the code and understand the issue, rather than running tests which are timing out. The issue says the tests are in
test/e2e/link-on-navigate-prop/index.test.tswhich doesn't exist. But let me look at what tests exist.Let me understand what's happening by reading the code and tests more carefully.
- Assistant
Let me check if
vpis the tool to run tests. - Assistant
Let me check if vp is installed locally or via npx.
- Assistant
Let me try running vitest directly:
- Assistant
Let me check the node_modules directory for bin files.
- Assistant
Let me try running tests using the vp command:
- Assistant
Good, unit tests pass. Now let me understand what the issue is about. The issue says ~8 test failures from
test/e2e/link-on-navigate-prop/index.test.ts. Let me check if there's a .nextjs-ref directory and look at the Next.js reference: - Assistant
Let me search the Next.js test files in node_modules:
- Assistant
Let me try a broader search in the Next.js package for tests related to onNavigate. Next.js doesn't ship tests in node_modules. Let me look at the CI link mentioned in the issue to understand what tests are failing.
Looking at the issue more carefully, it says:
- The
onNavigatecallback prop on<Link>(added in Next.js 15) does not fire - ~8 test failures
- Affected Test Suites:
test/e2e/link-on-navigate-prop/index.test.ts
This is a Next.js test suite that runs against vinext. Let me look at the existing e2e tests to understand what's needed. The issue says to reproduce first, then study the Next.js implementation, and implement.
Looking at the current implementation in
link.tsx, I can seeonNavigateIS implemented. ThehandleClickfunction does:- Creates a NavigateEvent with
url,preventDefault(), anddefaultPrevented - Calls
onNavigate(navEvent) - If
navEvent.defaultPrevented, returns early (skipping navigation)
This seems correct. But maybe the issue is that the tests from the Next.js repo test different behavior than what vinext currently supports.
- The
- Assistant
Let me look at the Next.js App Router link implementation to understand how onNavigate works there.
- Assistant
Now I can see the Next.js implementation. Let me understand what's going on. In Next.js 16 App Router's
linkClicked, theonNavigateevent only gets{ preventDefault }- nourlproperty. And importantly, it uses the_islocalurl.isLocalURLcheck before callingonNavigate.Let me check the Next.js 16 Pages Router link more carefully for the return value behavior:
- Assistant
Let me look at the test runner setup for Next.js compat tests:
- Assistant
Now I understand the structure. The issue refers to tests in the Next.js test suite
test/e2e/link-on-navigate-prop/index.test.tswhich runs against vinext's deployment. Let me look at the actual test runner setup to understand what test apps exist.Let me check the playwright config and see if there are any link-on-navigate tests.
- Assistant
Let me look at the playwright config and the overall test structure more carefully. The issue says this is about a Next.js test (
test/e2e/link-on-navigate-prop/index.test.ts) that fails when run against vinext. Let me understand what this Next.js test expects. - Assistant
Now let me understand what the actual issue is. The issue says the
onNavigateprop is "not implemented" but I can see it IS in the code. Let me look at what the Next.js test suite for this feature actually tests. Let me check if there's a reference to this test in the AGENTS.md or elsewhere: - Assistant
Let me look at the full link-navigation.test.ts file to see all onNavigate-related tests:
- Assistant
Let me look at the entire link-navigation.test.ts to understand what tests exist for onNavigate:
- Assistant
Let me look at what Next.js's test for
onNavigateactually tests: - Assistant
Let me look at the e2e tests more carefully. The issue says "test/e2e/link-on-navigate-prop/index.test.ts (8 failures)". Let me search the entire repository for any reference to this specific test.
- Assistant
Now I see! There's a comment in the link-navigation.test.ts that references the Next.js test. Let me look at what's currently ported and what might be missing.
- Assistant
Let me understand the full picture better. Let me look at the Next.js source for the App Router's Link to understand how onNavigate is handled differently:
- Assistant
Now let me understand the issue better. Let me look at what tests are currently in the link-navigation test file that test
onNavigatebehavior: - Assistant
Let me look at the Next.js test for link-on-navigate-prop to understand what's expected:
- Assistant
Let me look at the CI workflow to understand how Next.js tests are run against vinext:
- Assistant
Let me look at the Next.js 16 source code more carefully. Let me check if there's a newer API where
onNavigatereturns something: - Assistant
Let me now focus on what's really happening. Let me look at the full
handleClickfunction again and see if there's any issue with theonNavigatehandling: - Assistant
Let me look at the
toBrowserNavigationHreffunction to understand what it returns: - Assistant
Let me run the existing tests and also search for the Next.js test to understand what's expected:
- Assistant
Let me look at the full Next.js source code for the Link component to understand the full onNavigate API contract:
- Assistant
Now I understand the Next.js API. The
onNavigateevent only has{ preventDefault: () => void }- nourlproperty, nodefaultPreventedproperty. Let me look at the existing test fixtures for onNavigate and understand what tests from the Next.js deploy suite might be failing. Let me look for onNavigate-related test pages: - Assistant
Let me check if there's a way to access the Next.js test suite to understand what tests are expected:
- Assistant
Let me clone the Next.js reference to look at the actual test suite:
- Assistant
Now let me find the Next.js test file for onNavigate:
- Assistant
Let me read the Next.js test file:
- Assistant
Now let me see the test fixture pages:
- Assistant
Now I understand the test expectations. Let me also look at the app and pages router fixtures:
- Assistant
Let me continue reading the rest of the files.
- Assistant
Now I understand the test expectations. Let me look at the Next.js implementation of
linkClickedfor the app-router more carefully: - Assistant
Now let me look at the Next.js pages router link onClick handler:
- Assistant
Now I have a comprehensive picture. Let me understand the differences between vinext's implementation and Next.js's:
- External links with
replaceprop: In Next.js, when an external link hasreplace, it callse.preventDefault()+location.replace(href). Vinext doesn't handle this. - The
onNavigateimplementation itself looks correct but let me verify by looking at the full test expectations.
Let me now look at how the
handleClickfunction handles external links withreplaceto confirm this is the issue: - External links with
- Assistant
- Assistant
Let me look at the git log to see when onNavigate was added:
- Assistant
Let me search for when onNavigate was added:
- Assistant
Let me look at the CI workflow that runs Next.js deploy suite tests:
- Assistant
Let me look at the deploy test setup script:
- Assistant
Now I have a comprehensive understanding. Let me look at the full Next.js
linkClickedimplementation for both App Router and Pages Router, focusing on how external links withreplaceare handled, and howonNavigateinteracts with the flow: - Assistant
Now I understand the key differences. Let me check how vinext determines external URLs:
- Assistant
Let me look at these functions to understand how external URLs are determined:
- Assistant
Let me look at the
toBrowserNavigationHreffunction: - Assistant
Now I have a clear picture. Let me now understand the full Next.js test expectations. Let me also look at how the test is run in the deploy suite:
- Assistant
Now I have a clear picture. Let me analyze the key differences and understand what needs to be fixed. Let me first verify my understanding by looking at the
withBasePathandisAbsoluteUrlfunctions: - Assistant
Now I have a clear understanding of the issue. Let me look at the full picture:
The problem: Looking at the Next.js test
test/e2e/link-on-navigate-prop/index.test.ts, there are 7 tests × 2 routers = 14 test cases. The key issue is:-
External links with
replaceprop: Next.js callse.preventDefault()+location.replace(href), but vinext just returns early without handling thereplaceprop for external links. -
The
onNavigateevent object: Next.js only passes{ preventDefault: () => void }, but vinext passes{ url, preventDefault, defaultPrevented }- this is a superset so it should be compatible.
Let me verify my understanding by examining what happens with the replace test case. Then I'll implement the fix:
-
- Assistant
Now I have a complete understanding. Let me implement the fix. The core issue is:
- External links with
replaceprop: In Next.js, when an external link hasreplace, it callse.preventDefault()+location.replace(href). Vinext doesn't handle this case.
Let me now fix the link.tsx:
- External links with
- Assistant
Now let me look at how the props are destructured and used in the Link component:
- Assistant
Let me look at the full Link component to understand the destructuring:
- Assistant
Now I have a complete understanding. Let me trace through the key difference. Looking at Next.js's
linkClickedfunction:For external links:
if (replace) { e.preventDefault(); location.replace(href); } return;For local links:e.preventDefault(); onNavigate(...); navigate;In vinext's
handleClick, for external links it just returns without handlingreplace. Let me implement the fix: - Assistant
Now I have a clear picture. Let me trace through the key issues:
- External links with
replace: Next.js handles this withe.preventDefault()+location.replace(href). Vinext just returns early. - onNavigate should be called for internal links: The code looks correct, but let me verify.
Let me now implement the fix. The main change is in the external link handling section:
- External links with
- Assistant
Now I understand the full picture. Let me implement the fix. The key difference between Next.js and vinext is in the external link handling:
Next.js (for external links):
if (!isLocalURL(href)) { if (replace) { e.preventDefault(); location.replace(href); } return; }Vinext (current - missing replace handling for external links):
if (isAbsoluteOrProtocolRelativeUrl(resolvedHref)) { const localPath = toSameOriginAppPath(resolvedHref, __basePath); if (localPath == null) return; // truly external - just returns! }Let me fix this:
- Assistant
Now I understand the full picture. Let me implement the fix. The key issue is that for external links, Next.js handles the
replaceprop by callinge.preventDefault()andlocation.replace(href), but vinext just returns early without handlingreplace. Let me fix this: - Assistant
Good, the fix is in. Now let me run the existing tests to make sure nothing is broken:
- Assistant
Good, existing tests pass. Let me also run the shims test:
- Assistant
All existing tests pass. Now let me think about whether there are more issues. Looking at the Next.js test file more carefully, I realize the main fix (external links with
replace) addresses theshould replace history state for external links with replace proptest. But the issue says "~8 test failures".Let me look more carefully at the issue. The issue mentions:
onNavigatecallback never fires on click- Click state tracking broken
- History state replacement via
onNavigatereturn value not working
Let me look at the existing test fixtures to see if there are E2E tests that exercise onNavigate more fully. Let me check the e2e tests:
- Assistant
Let me now write a quick test to verify the fix works for the external link with replace case:
- Assistant
Let me run all the relevant tests to verify nothing is broken:
- Assistant
All 954 tests pass. Let me verify the diff is correct:
- Assistant
The diff looks clean. Now let me verify the fix is complete by reviewing the entire handleClick function to ensure it properly matches the Next.js behavior:
- Assistant
The code looks correct. Let me verify there are no TypeScript errors:
- Assistant
Those are pre-existing node_modules TypeScript errors, not related to my change. Let me try running the project's lint/type check:
- Assistant
No TypeScript errors in my change. Let me run the full unit test suite to make sure nothing is broken:
- Assistant
The full test suite takes too long. Let me run the key test files that are most relevant:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.