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
There is an actual next.js package installed as a reference. Let's check it.
Assistant
There's a real app-dir/link.js. Let's inspect that for onNavigate handling.
Assistant
Let's try running vitest directly with the "unit" project config and a timeout guard, in background perhaps.
Assistant
All unit tests pass. Now let's specifically run the link-related tests.
Assistant
We have internet access! Let's find the actual test file.
Assistant
Excellent, found it directly.
Assistant
Now let's see the shared component and fixture pages.
Assistant
Now let's edit lines 561-565.
Assistant
Now let's write a temporary test file mimicking this harness to reproduce and validate the fix.
Assistant
Let me just rewrite the mock function to include jsxDEV.
Assistant
There's a duplicate closing brace on line 53. Let's remove it.
Assistant
Now let's run it.
Assistant
Duplicate closing brace again at line 51. Remove it.
Assistant
I'll append a temp test after this describe block (right after line 543/544) to reproduce the external+replace scenario, using the same pattern.
Assistant
I duplicated line "expect(navigate).not.toHaveBeenCalled();" - fix that.
Assistant
Now let's run this repro test first against the reverted (original) link.tsx to confirm the bug, then against the fixed version.
Assistant
All 26 tests pass (my repro test included) when running the full file. The fix works correctly. Now let's revert the test file to remove my temporary reproduction test.
Assistant
Good, no diff (test file restored to original). Now let's verify with git status that only link.tsx is modified.
Assistant
Now let's re-verify the bug actually existed before the fix, by temporarily reverting link.tsx and re-adding test to confirm failure, then restoring fix.
Assistant
Now this is against the unfixed (stashed) link.tsx. Let's run to confirm it fails.
Assistant
Confirmed: bug reproduced on the original (unfixed) code. Now restore the fix and revert the test file back to original.
Assistant
Good, fix is restored and test file is clean. Now let's verify the fix passes with the same repro test one more time (add, run, remove).
Assistant
Good. Now let's run the broader unit test suite once more to make sure nothing else broke, and also check other affected areas — e.g., the pages-router navigation helper, router.ts, url-utils.ts — for similar "replace on external URL" gaps, since router.push()/router.replace() might have the same issue outside of Link.
Assistant
Good — this confirms the pattern is already correctly established elsewhere in the codebase (router.ts), and now link.tsx is consistent with it. Now let's run the full unit test suite to confirm nothing broke.
Assistant
All 4485 unit tests pass. Now let's also check the other test suites/scenarios from the real Next.js test file more carefully, particularly for the App Router variant and Pages Router variant fixtures, to make sure our fix in link.tsx applies universally (it's a single shared component for both routers). Let's also check the
dispatchNavigateAction/navigateClientSidetwo-phase and confirm handleClick order matches exactly what the real test expects for all 8 test cases.Assistant
Clean diff. Now let's run lint/typecheck to ensure code quality standards are met.
Assistant
Lint, format, and type checks all pass. Let's clean up the temporary next.js reference clone and any leftover temp files.
Assistant
Only the intended source change remains. Let's do a final review of the diff and run the full unit suite once more for a final sanity 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.