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
Let me start by exploring the repository structure to understand what we're working with.
Assistant
Good, I see
onNavigateis already defined in the Link props. Let me look at the implementation of the Link component to see how it currently handlesonNavigate.Assistant
Now let me look at the Next.js implementation to understand the API contract.
Assistant
me look at the existing tests for
onNavigateto understand what's expected.Assistant
Now let me look at the existing test suite that is supposed to fail.
Assistant
Let me look at the existing tests to understand patterns used.
Assistant
Now let me look at the actual Next.js implementation of onNavigate to better understand its semantics.
Assistant
Let me look at the existing test fixture for navigation:
Assistant
Now let me look at the e2e navigation test for app router:
Assistant
Let me look at the existing link.tsx onNavigate implementation more carefully and the issue.
Assistant
me look at the existing implementation more carefully:
Assistant
Now let me look at the Next.js test to better understand the expected behavior. Let me search for related files in the system.
Assistant
Let me look at the existing implementation in
link.tsxandlink-navigation.test.tsto understand what's going on, and create a simple repro:Assistant
Tests pass currently. Let me look at the existing e2e test for
onNavigateand create a repro script to verify the issue.Assistant
Let me look at how the current implementation handles the URL construction. The issue may be that
absoluteFullHrefdoesn't produce the right URL.Assistant
me search for any Next.js related references in the codebase:
Assistant
Now let me look at the existing test in link-navigation.test.ts to understand how it's tested.
Assistant
Let me understand more about what the issue really is. Let me look at the existing implementation of
onNavigatemore carefully and check the Next.js Test Suite by searching foronNavigatereferences in shims and other places:Assistant
Let me search for any reference to onNavigate in node_modules:
Assistant
Now let me look at the Next.js link.js implementation:
Assistant
me search for the Next.js test file or its specific behaviors:
Assistant
Let me also check the existing implementation for the test that already exists:
Assistant
Let me look at the issue from a different angle - what's the actual reproduction. Let me run a quick test to check whether the existing tests pass with
onNavigateand what's the issue.Assistant
Now let me look at how to reproduce this issue. Let me write a small test that creates a Link with onNavigate and verifies it gets called.
Assistant
Now let me look at the test case for download links - it does call
onNavigatewith thenavigatemock set up. So when clicking a non-download link, theonNavigateshould be called.Let me write a test reproduction script to verify the issue:
Assistant
The capture mock isn't working. Let me look at the existing test that does work and copy that structure:
Assistant
Let me adjust my test to use the right approach. Looking at the existing test, it uses
mockReactAnchorCaptureForLinkOnly_DO_NOT_REUSEwhich is a tactical function in the existing test file. Let me update my test:Assistant
look at the actual Next.js test patterns. Let me look at what version of Next.js we have and what's tested:
Assistant
Assistant
Now let me look more carefully at the test for the relative query hrefs:
Assistant
Let me search for any related deploy tests:
Assistant
Let me check what the e2e tests for pages router look like to understand the expected behavior:
Assistant
Let me check the app router nav-link-test fixture:
Assistant
Let me look for any related Next.js test files that may have been referenced:
Assistant
Let me look at the next.js test fixture and see what's expected. Let me also see what tests exist in the test directories that might match.
Assistant
Let me write a more comprehensive reproduction test to verify the actual behavior:
Assistant
Let me look for the actual Next.js test files in node_modules or the package source:
Assistant
me try to fetch the actual Next.js test file:
Assistant
Now I have the actual test file. Let me see the rest of it:
Assistant
Excellent! Now I have the actual test file! Let me get the corresponding fixtures:
Assistant
Let me look at the Pages Router fixture:
Assistant
Let me check if there are any other test setups that might be running Next.js tests against vinext:
Assistant
Let me look at the implementation more carefully and the surrounding code to understand the full picture:
Assistant
Now let me create the test fixture locally to verify what's happening. Let me first add the test to vinext's e2e tests:
Assistant
Now let me set up a test fixture similar to the Next.js one to verify the behavior:
Assistant
Now let me try to start the dev server and run the e2e tests:
Assistant
Now let me actually try to run the e2e tests to see what happens:
Assistant
Now let me start the dev server and run the tests:
Assistant
Let me try to start the dev server and run the test:
Assistant
There's a parse error in another file. Let me check if my fixture is the issue or another file:
Assistant
Let me focus on running the unit tests instead. The dev server has a pre-existing issue. Let me first run the existing onNavigate unit tests to confirm what passes:
Assistant
me check if there are any reference source files:
Assistant
Let me look at the Pages Router implementation:
Assistant
Let me check the full implementation of handleClick:
Assistant
Now let me make the fix. The main issue is that for external links with the
replaceprop, the browser pushes a new history entry instead of replacing. Let me fix this:Assistant
Now let me make the fix. The change is: for external links with
replace, calle.preventDefault()andlocation.replace(href):Assistant
Let me verify the change:
Assistant
Now let me run the tests to make sure they still pass:
Assistant
Now let me verify my repro tests still pass:
Assistant
Now let me add a test case for the external link with replace scenario to my reproduction tests:
Assistant
All 7 tests pass. Let me now run the original tests to verify they still pass:
Assistant
All 1042 tests pass. Now let me also verify the fix works correctly by checking what happens before the fix would have failed:
Assistant
Let me also check if the Pages Router needs a similar test fixture:
Assistant
Now let me think about edge cases. Let me also check what happens if the URL is a relative URL with a domain:
Assistant
Let me check if there are any other tests I should run to verify the changes:
Assistant
Now let me clean up the test fixture files I created that I don't need:
Assistant
Now let me also look at the dist file to see if there's a compiled version that needs to be rebuilt:
Assistant
Let me verify the dist directory isn't being used by tests:
Assistant
Good, the dist directory is not imported by tests. Tests use the source files directly.
Let me also check the build process to ensure that the dist file is updated when needed:
Assistant
Let me run all the link-related tests to make sure nothing is broken:
Assistant
Now let me also rebuild the dist file to match the source change:
Assistant
The dist file is rebuilt with the new fix. Let me also run the full unit tests to make sure everything still passes:
Assistant
All 4485 unit tests pass. Now let me also think about other edge cases. Let me also look at the implementation once more to see if there are any other improvements needed.
Assistant
Let me also check protocol-relative URLs:
Assistant
Let me verify the change is correct:
Assistant
Let me check if the dist file's
onNavigatehandling is different:Assistant
Let me verify the changes once more and run all the relevant tests:
Assistant
Wait, looking at this more carefully, I realize I should also check whether the dist file is part of the submission. Let me check the git
Assistant
Good,
dist/is in.gitignore, so the dist files are not part of the submission. The source file is what matters.Wait, but actually, let me check if there's a special place where dist files are tracked for this repo. Let me look at git ls-files for dist
Assistant
Let me look at the full implementation once more to check for any other potential issues:
Assistant
Let me verify my fix doesn't break existing tests by running the most relevant test suites:
Assistant
All 1042 tests pass. Now let me think about whether there are any other improvements I should make. Let me also check the existing implementation against the recommendations in the issue:
Assistant
me run the lint and check to make sure my changes are good:
Assistant
Lint passes for our file. Let me also verify the formatting:
Assistant
Formatting passes. Now let me also think about whether there are any other tests that might be affected by this change:
Assistant
Let me search for tests that might be affected by my changes:
Assistant
No tests directly test for "truly external" or similar strings. Let me also check the test files for any tests that might be testing the click handler for external links:
Assistant
These tests are about rendering, not click behavior. They should still pass with my change.
Let me also check the existing tests for click behavior on external links.
Assistant
No tests for external link click behavior. Let me also run all the tests once more to confirm everything works:
Assistant
All 4485 unit tests pass. Let me also verify the changes look correct one more time:
Assistant
me check the existing tests one more time:
Assistant
All 5 onNavigate tests pass. Let me now also verify by writing a simple test that reproduces the fix scenario:
Assistant
me clean up the temporary files:
Assistant
Now let me check the final diff:
Assistant
Now let me do a final check on the implementation and review all the changes:
Assistant
Let me also verify the dist file has been rebuilt with the fix:
Assistant
The dist file is updated. Let me also run a final comprehensive test to make sure everything works:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.