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.
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 callsubmit) usinggit statusor 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 understanding the repository structure and the issue at hand. The issue is about
onNavigatecallback prop on<Link>not being implemented. Let me first explore the repository structure, then look at the Next.js reference implementation, and then implement the fix.Let me start by exploring the repository.
Assistant
Let me explore the packages and find the relevant link component implementation
Assistant
There's a
vinextpackage. Let me explore it.Assistant
Let me explore the source directory.
Assistant
Let me look at the shims and client directories.
Assistant
Let me run these as separate commands.
Assistant
Let me look at the Link component source code and the Next.js reference implementation.
Assistant
Let me look at more of the file, particularly the Link component implementation.
Assistant
Let me find the Link component implementation
Assistant
Let me look at the Link component implementation starting from line 393 and the onNavigate handling around line 570
Assistant
Let me scroll down to see the click handler and onNavigate code
Assistant
Let me look at the test file to understand the expected behavior and also check the dist version of this file
Assistant
Let me search for test files related
Assistant
Let me look at the test file for Link
Assistant
Let me search for onNavigate in the test file
Assistant
Let me look at the dist version to see if the built version matches and also explore the Next.js reference implementation
Assistant
Let me find the Next.js reference implementation
Assistant
Let me search for onNavigate across the codebase
Assistant
Let me look at the Next.js App Dir link implementation and the existing tests
Assistant
Let me look at the existing test cases for onNavigate
Assistant
Let me look at the link-navigation test for onNavigate
Assistant
Let me run the relevant tests to see what the current failures look
Assistant
Let me try running tests differently
Assistant
Let me check package.json for test scripts
Assistant
Let me try running with vp
Assistant
Let me run the link tests and shims tests too
Assistant
Let me check the e2e tests for onNavigate
Assistant
Let me look at the fixture for the onNavigate test
Assistant
Let me check the dist version to see if it matches the source
Assistant
Let me look at the Next.js ESM link implementation more closely
Assistant
Let me also look at the Pages Router version of Next.js link
Assistant
Let me look at the end of the Link component to see how the anchor element is rendered
Assistant
Let me compare the dist and source to see if they match
Assistant
Let me look at the app router e2e test for onNavigate
Assistant
Let me look at the app router fixture for onNavigate test
Assistant
Let me check the Next.js type definition for onNavigate
Assistant
Let me look at the
toBrowserNavigationHreffunctionAssistant
Let me see the function.
Assistant
Let me check if dist is up to date
Assistant
Let me look at the Next.js source code more carefully. Let me check if there's a
.nextjs-refdirectoryAssistant
Let me look at the full Pages Router link.js from Next.js
Assistant
Let me look at the full dist file for the Link component to see if there's a discrepancy
Assistant
Let me check the vinext type definition for onNavigate
Assistant
Let me look at the full link-navigation test for onNavigate
Assistant
Let me search for more onNavigate tests in the test file
Assistant
Let me check the dist type definitions for onNavigate
Assistant
Let me create a reproduction script to test the onNavigate behavior
Assistant
Let me check the normalizePathTrailingSlash function
Assistant
Let me check git history for onNavigate related changes
Assistant
Let me check git history for the link file
Assistant
Let me search for the commit that introduced onNavigate
Assistant
Let me find when onNavigate was first added
Assistant
Let me create a proper reproduction script to test onNavigate
Assistant
Let me search for the Next.js test file in node_modules
Assistant
Let me run all unit tests to find any failures
Assistant
Let me look at the e2e test configuration
Assistant
Let me check how the package exports are configured
Assistant
Let me search for Next.js test files related to onNavigate in node_modules
Assistant
Let me search for onNavigate in the Next.js source code more broadly
Assistant
Let me look at how vinext intercepts the next/link import
Assistant
Let me look at how next/link is resolved in the vinext plugin
Assistant
Let me look at the full Next.js linkClicked function for the Pages Router
Assistant
Let me look at the full next-shims.d.ts type definition for Link
Assistant
Let me check git log for onNavigate related commits
Assistant
Let me look at the commit that fixed onNavigate URL resolution
Assistant
Let me look at the diff for this commit
Assistant
Let me look at the router.ts onNavigate implementation
Assistant
Let me look at the AGENTS.md file for context
Assistant
Let me write a quick test script to verify onNavigate behavior
Assistant
Let me check the vinext build configuration
Assistant
Let me look at how the vinext plugin resolves next/link
Assistant
Let me check what shimsDir is
Assistant
Let me check the Next.js version
Assistant
Let me look at the full Next.js link.d.ts file
Assistant
Let me check the App Router link.d.ts
Assistant
Let me look at the CI configuration
Assistant
Let me look at the Next.js Deploy Suite configuration
Assistant
Let me search for references to the Next.js test file in the vinext codebase
Assistant
Let me look at the full Next.js linkClicked function for the Pages Router
Assistant
Let me look at the scripts for running Next.js tests
Assistant
Let me check if dist is in sync with source by looking at git status
Assistant
Let me now focus on implementation. I've analyzed the code and found that
onNavigateIS implemented but there's a missing piece:setPending(true)is not called for Pages Router navigation, which breaks click state tracking. Additionally, I need to verify theonNavigatecallback actually fires. Let me first add a unit test to verify onNavigate fires, then fix the pending state issue.Let me look at the test file to understand the test patterns
Assistant
Let me look at the test helper functions to understand the test patterns
Assistant
Let me look at the test that verifies onNavigate is NOT called for download
Assistant
Now I have a thorough understanding of the codebase. Let me look at the current implementation one more time and identify the issues:
- The
onNavigatecallback IS implemented and should fire synchronously - However,
setPending(true)is NOT called for Pages Router navigation, breaking click state tracking - The
onNavigateevent shape differs from Next.js (vinext addsurlanddefaultPrevented)
Let me now fix the issues. First, let me look at the full handleClick function to understand the Pages Router branch
- The
Assistant
Now I have a clear understanding. Let me make the changes:
- Fix click state tracking for Pages Router: Add
setPending(true)andsetPending(false)for Pages Router navigation - Add a unit test to verify
onNavigatefires on click
Let me start with the code fix:
- Fix click state tracking for Pages Router: Add
Assistant
I see there's an extra closing brace. Let me fix the indentation issue
Assistant
Let me see the current state of the affected area
Assistant
Let me fix this properly by replacing the entire block
Assistant
Good, the code looks correct now. Let me run the tests to verify
Assistant
Good, tests pass. Now let me update the dist file to match the source change. Let me check if there's a build command
Assistant
Let me verify the dist was updated correctly
Assistant
Let me verify the full Pages Router branch in the dist
Assistant
Good, the dist is updated. Now let me run all the unit tests to verify nothing is broken
Assistant
Now let me add a unit test to verify
onNavigatefires on click. Let me look at the test file to find where to add itAssistant
Let me add a test to verify onNavigate fires on click. Let me look at the current test that tests onNavigate for download
Assistant
Let me add a test to verify onNavigate fires on click. I'll add it after the download test
Assistant
Let me run the new tests
Assistant
All tests pass. Let me now run the full test suite to make sure nothing is broken
Assistant
All tests pass. Let me review the changes I've made
Assistant
Let me now verify the final state of the implementation by looking at the key parts of the source code
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.