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 relevant files. Let's first get an overview.
- Assistant
Let me explore the repository structure more broadly to understand what we're working with.
- Assistant
Let me look for the link component and the test that's failing.
- Assistant
Let me look at the link shim implementation and the test file for the onNavigate prop.
- Assistant
Let me look at the e2e test file for link-on-navigate-prop and the Link component implementation.
- Assistant
Let me look at the relevant test files and the Link component implementation.
- Assistant
Let me look at the Link component source code and the onNavigate test.
- Assistant
Let me look at the Link component source code and see if onNavigate is handled there.
- Assistant
I can see that the Link component already has
onNavigatesupport implemented. Let me look at the test file to understand what specific tests are failing. - Assistant
Let me look for the e2e test file mentioned in the issue description:
test/e2e/link-on-navigate-prop/index.test.ts - Assistant
The directory doesn't exist. Let me look at what e2e tests exist.
- Assistant
Let me check the link-navigation.test.ts file for onNavigate related tests.
- Assistant
Let me check what tests exist in the link-navigation.test.ts file related to onNavigate.
- Assistant
Let me look at the full test file and the shims test file for onNavigate tests.
- Assistant
Let me look at the shims.test.ts for the onNavigate tests more thoroughly.
- Assistant
Let me check the e2e test file for onNavigate:
- Assistant
Let me look at the test files that relate to onNavigate and check the pages router link-advanced spec:
- Assistant
Let me look for the specific test mentioned in the issue:
- Assistant
Let me look at the Next.js reference implementation to understand the onNavigate API contract:
- Assistant
Let me run the existing tests to see what's failing:
- Assistant
Let me look at the full link-navigation test to find the onNavigate tests:
- Assistant
Let me search through the link-navigation.test.ts to find all tests related to onNavigate.
- Assistant
Let me search for all onNavigate-related describe blocks:
- Assistant
Let me check the test fixtures and the link component more carefully:
- Assistant
Now let me check the relative-query-link.tsx in app-basic:
- Assistant
Now let me understand what specific tests from the Next.js
test/e2e/link-on-navigate-prop/index.test.tsneed to work. Let me check if there's a.nextjs-refor any reference to the Next.js source: - Assistant
Let me check the AGENTS.md for guidance:
- Assistant
Let me clone the Next.js repo and look at the onNavigate test:
- Assistant
Now let me look at the Next.js test for link-on-navigate-prop.
- Assistant
Now let me look at the Next.js test fixtures to understand what the test app looks like:
- Assistant
Let me look at the shared OnNavigate component and the test pages:
- Assistant
Now let me look at the Next.js implementation of
onNavigatein their Link component: - Assistant
Let me look at the actual implementation of onNavigate in the Next.js link component:
- Assistant
Let me see more of the Next.js link implementation to understand how onNavigate works with external links:
- Assistant
Let me look at the Next.js link implementation more carefully to understand the onNavigate event shape:
- Assistant
Let me look at the
renderIsolatedLinkfunction and the existing test structure: - Assistant
Let me look at how props are destructured in the Link component to see if
onNavigateis actually getting passed through: - Assistant
Let me look at how props are destructured and the full flow.
- Assistant
Let me look at the existing test case for download links with onNavigate in the test file:
- Assistant
Let me run the existing tests to see what's passing and what's failing:
- Assistant
Let me try running with vp instead:
- Assistant
Let me look more carefully at the tests and understand the actual issue. Let me look at the full test file to see all the tests related to onNavigate:
- Assistant
Let me understand the exact issue by looking at the Next.js implementation vs vinext's implementation more carefully:
- Assistant
Now let me look at the full Next.js implementation to understand the
linkClickedfunction and howonNavigatefits in: - Assistant
Now let me look at the full handleClick flow in vinext's Link component:
- Assistant
Let me now look at the actual test that's failing. The issue refers to
test/e2e/link-on-navigate-prop/index.test.tsfrom Next.js. Let me check if vinext has equivalent tests or fixtures: - Assistant
Now let me look at the actual test structure for the link-on-navigate-prop tests. Let me check if there's an E2E test in vinext for this:
- Assistant
Let me try running just the specific tests related to onNavigate:
- Assistant
Let me check how tests are run:
- Assistant
Let me try using
vp test run: - Assistant
Let me check the node_modules for vp
- Assistant
Let me try running the test with npx:
- Assistant
Good - all 25 existing link-navigation tests pass. Now let me run the shims test:
- Assistant
Let me look at the existing E2E test for onNavigate in the pages-router link-advanced test more carefully:
- Assistant
OK, let me understand the issue better. The issue is about the
test/e2e/link-on-navigate-prop/index.test.tsfrom Next.js having 8 test failures when run against vinext. Let me look at what tests that file has and compare against vinext's behavior.Let me now look at the key differences between vinext and Next.js
onNavigateimplementations: - Assistant
Now I can see the key differences. Let me look at the Next.js test fixture pages to understand the full test expectations:
- Assistant
Wait, this doesn't have the OnNavigate component. Let me check the layout:
- Assistant
Let me look at the pages-router pages too:
- Assistant
Let me check the _app.tsx and the layout.tsx for the pages router:
- Assistant
Now I have a thorough understanding of the issue. Let me compare the Next.js implementation vs vinext's implementation:
Key differences I found:
-
External links with
replaceprop: Next.js callse.preventDefault(); location.replace(href)for external URLs withreplace. Vinext just returns early without handling replace. -
onNavigateevent shape: Next.js passes only{ preventDefault: () => void }. Vinext passes{ url, preventDefault, defaultPrevented }- which is actually more. -
onNavigateis only called for local URLs: In Next.js,onNavigateis never called for external links, download links, or modifier-key clicks. Vinext matches this behavior.
Now let me trace through what happens for each of the 8 tests in
test/e2e/link-on-navigate-prop/index.test.ts:The test file has 7 tests × 2 routers (App/Pages) = 14 total. Let me check what specific test failures would occur. The issue says "~8 test failures".
Let me look more carefully at the Next.js implementation flow for the test fixture:
-
- Assistant
Now I have a clear understanding of the problem. Let me compare the two implementations carefully:
Next.js
linkClickedfunction flow:- Check modifier/download → return early (no
onNavigate) - External URL check → if external: handle
replacewithlocation.replace(), return (noonNavigate) e.preventDefault()- Call
onNavigate({ preventDefault }) - If
preventDefault()was called → return (no navigation) - Navigate
vinext
handleClickfunction flow:- Call
onClick - Check
e.defaultPrevented - Check download → return early
- Check modifier keys → return early
- Check target → return early
- External URL check → return early (no
replacehandling!) e.preventDefault()- Call
onNavigate({ url, preventDefault, defaultPrevented }) - If
defaultPrevented→ return - Navigate
- Check modifier/download → return early (no
- Assistant
Let me look at the existing E2E test fixtures that test onNavigate:
- Assistant
Now I have a clear picture. Let me look at the exact differences between Next.js and vinext:
Key finding from the Next.js
linkClickedfunction:- For external links with
replace: Next.js doese.preventDefault(); location.replace(href)— vinext does NOT do this - The
onNavigateevent in Next.js only has{ preventDefault }— nourlordefaultPrevented onNavigateis only called for LOCAL (internal) URLs in both implementations
Let me now implement the fix. The main issues are:
- External links with
replaceneede.preventDefault(); location.replace(href) - Add proper unit tests for the onNavigate behavior
- For external links with
- Assistant
Now let me implement the fix. I need to:
- Add
e.preventDefault(); location.replace(href)for external links withreplaceprop - Write tests for the onNavigate behavior
Let me first make the fix:
- Add
- Assistant
Let me navigate to the handleClick function:
- Assistant
Now let me look at the full handleClick to understand the complete flow:
- Assistant
Now I have a clear picture of the issue. Let me trace through the key differences:
Next.js
linkClickedflow:- Check modifier/download → return early (onNavigate NOT called)
- Check if external URL → if
replace, doe.preventDefault(); location.replace(href), return (onNavigate NOT called) e.preventDefault()- Call
onNavigate({ preventDefault }) - If preventDefault called → return
- Navigate
vinext
handleClickflow:- Call
onClick - Check defaultPrevented, download, modifier, target → return early
- Check external → return (MISSING: replace handling for external links)
e.preventDefault()- Call
onNavigate({ url, preventDefault, defaultPrevented }) - If defaultPrevented → return
- Navigate
The main bug is #3: External links with
replacedon't calle.preventDefault(); location.replace(href).Let me fix this:
- Assistant
Let me use the correct edit syntax:
- Assistant
Good, the fix is in place. Now let me add comprehensive tests for the onNavigate behavior to the link-navigation test file. Let me first look at the current test structure:
- Assistant
Let me look at the test for the download link with onNavigate - that's the existing onNavigate test pattern:
- Assistant
Now let me add the onNavigate tests to the test file. Let me first look at the end of the "Link App Router navigation scheduling" section:
- Assistant
Now let me add the onNavigate tests. I'll add them after the download link test, still within the "Link App Router navigation scheduling" describe block:
- Assistant
Now let me run the tests to see if they pass:
- Assistant
Parse error at line 1045. Let me check that area:
- Assistant
There's an extra
});at line 1045. Let me fix this: - Assistant
I see the issue - there's an extra
});from the original describe block. Let me fix it: - Assistant
Good, the syntax error is fixed. Let me run the tests again:
- Assistant
All 32 tests pass. Let me also run the shims tests and the link test to make sure nothing is broken:
- Assistant
All tests pass. Let me also verify the built dist files need updating:
- Assistant
Good, the build succeeds. Let me verify the change is in the built output:
- Assistant
Let me check the built code for the external links with replace:
- Assistant
The fix is properly reflected in the built output. Let me also make sure the dist declaration file doesn't need changes (it shouldn't since we didn't change the type interface):
- Assistant
Good. Now let me verify the git diff to make sure everything looks correct:
- Assistant
Good. Let me verify the full diff looks correct.
- Assistant
The diff looks correct. Let me now do a final review of the checklist and make sure everything is complete:
- Assistant
Let me run all related tests one more time to confirm everything passes:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.