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 exploring the repository structure to understand what we're working with. This appears to be a Next.js shim/implementation called "vinext". I need to:
- Understand the repository structure
- Find the Link component implementation
- Study the Next.js reference implementation for
onNavigate - Implement the
onNavigateprop - Test it
Let me begin by exploring the repository.
Assistant
Let me look at the packages directory and find the Link component.
Assistant
Let me explore the vinext package.
Assistant
Let me look at the src directory in vinext.
Assistant
I found the Link component. Let me look at the relevant files: the Link shim, the prefetch helper, and the Next.js reference implementation.
Assistant
The open command doesn't take file as a keyword argument. Let me check the available commands again. It says
Usage: open [OPTIONS] [FILE] [LINE_NUMBER]. So I should just pass the file path as a positional argument.Assistant
Now let me look at the test file and the Next.js reference implementation to understand what's expected.
Assistant
Let me search more broadly for the test.
Assistant
Let me search for e2e tests that might be related to `onNavigate
Assistant
Let me look at the Next.js implementation for
onNavigatein node_modules, and also check the test for link-relatedAssistant
Now let me check the test file for link and the Next.js implementation more thoroughly
Assistant
Let me search for the specific e2e test mentioned in the issue
Assistant
Let me look at the e2e test directory and also the Next.js link implementation more closely to understand the API contract.
Assistant
Let me look for the Next.js reference and also understand the current implementation issues
Assistant
Let me look at the full Next.js
link.jsfile from node_modules to understand the complete API contractAssistant
Let me read the full file.
Assistant
Let me look at the full link.tsx file carefully, particularly the props destructuring
Assistant
Let me look at the beginning of the component definition and the props destructuring.
Assistant
Let me see the full destructuring from the Link component
Assistant
Let me look at the full handleClick function
Assistant
Let me get the rest of the handleClick function
Assistant
Let me create a test script to reproduce the issue and verify whether
onNavigatefiresAssistant
Let me check the test setup and try running a simpler test
Assistant
Let me run the existing link unit tests to see their status
Assistant
Let me look at the vitest configuration and try a simpler approach
Assistant
Let me check the built dist version of link to see if onNavigate is properly included
Assistant
Let me look at the dist file's handleClick function
Assistant
Let me look at the Next.js type definitions for Link and onNavigate
Assistant
Let me look at recent git history for the link component
Assistant
Let me search for the Next.js test for onNavigate in the node_modules
Assistant
Let me look at the link-navigation test and also try to run a quick test
Assistant
Let me try to create a minimal reproduction script and test it
Assistant
Let me try running the repro from within the project directory
Assistant
Let me search for all occurrences of "onNavigate" in the repo
Assistant
Let me look at the test fixtures and tests to understand the expected behavior
Assistant
Let me check the pages fixture and the e2e tests
Assistant
Now let me look at the e2e tests for onNavigate
Assistant
Let me check the pages-router e2e test
Assistant
Let me check the existing unit tests for onNavigate
Assistant
Let me look at the link-navigation test more thoroughly, specifically around line 508
Assistant
Let me verify the dist file matches the source for onNavigate functionality
Assistant
Let me look at the full link-navigation test file to understand all the link-related test cases
Assistant
Let me look at the link-navigation test from line 508 onwards
Assistant
Let me search for Next.js test patterns related to onNavigate
Assistant
Let me check the Next.js link.js more carefully for any return value handling
Assistant
Let me look at the fixtures used in the e2e tests for navigation
Assistant
Let me check the git history for onNavigate in link.tsx
Assistant
Let me search git log for the first addition of onNavigate
Assistant
Let me check the initial commit for onNavigate content
Assistant
Let me look at the initial commit's handleClick to see if there were issues
Assistant
Let me look at the full navigation spec and the link-advanced spec for onNavigate context
Assistant
Let me check how next/link resolves in vinext
Assistant
Let me find how next/link is resolved to the vinext shim
Assistant
Let me look at the next-shims.d.ts to see how onNavigate is typed
Assistant
Let me look at the toBrowserNavigationHref and resolveRelativeHref functions
Assistant
Let me look at these functions.
Assistant
Let me look at the commit that fixed onNavigate URL resolution
Assistant
Let me look at the
toSameOriginAppPathfunctionAssistant
Let me look at this function.
Assistant
Let me look at the test comment about Issue #38
Assistant
Let me check what the current state of the link.tsx onNavigate implementation is relative to the Next.js one, and see if there are any recent changes
Assistant
Let me check if the e2e tests can be run
Assistant
Let me look at the full link-advanced e2e spec
Assistant
Let me look at the full link-navigation test to find all onNavigate-related tests
Assistant
Let me create a test to verify onNavigate fires correctly
Assistant
Let me try running this test
Assistant
Let me try a simpler approach using node directly
Assistant
Let me use plain node
Assistant
Let me look at `isDangerousScheme
Assistant
Let me look at the url-safety file
Assistant
Let me check if there's a Next.js reference or tests directory somewhere
Assistant
Let me look at the pages-router-link-navigation module
Assistant
Let me search more broadly for any reference to the Next.js test
Assistant
Let me check if the dist is up to date with the source
Assistant
Let me look at the Next.js link API type definition
Assistant
Let me look at Next.js's client/link type definition
Assistant
Let me look at the
withBasePathfunctionAssistant
Let me find where withBasePath is defined
Assistant
Let me look at the withBasePath function
Assistant
Let me try to directly test the Link component with onNavigate
Assistant
Let me look at the dist link.js more carefully around the onNavigate code
Assistant
Let me search for any .nextjs-ref or similar reference
Assistant
Let me check git blame for the onNavigate-related lines
Assistant
Let me search for any error logs or CI artifacts
Assistant
Let me look at the commit that referenced the Next.js test
Assistant
Let me look at this commit
Assistant
Let me compare the dist file and source for completeness
Assistant
Let me look at recent commits to see if there's a regression
Assistant
Let me look at commit 7d1f482
Assistant
Let me try to run just the link-advanced e2e test for pages router
Assistant
Let me check how next/router is resolved in vinext
Assistant
Let me look at how next/router is provided
Assistant
Let me try to run the unit tests for link
Assistant
Let me try running a simpler test using the vite-plus test runner
Assistant
Let me check how to run tests in this project
Assistant
Let me try running tests with vp
Assistant
Let me run the shims tests
Assistant
Let me run the link-navigation tests
Assistant
Let me look at the AGENTS.md file for context
Assistant
Let me carefully compare the onNavigate code in source vs dist
Assistant
Let me search for any Next.js documentation about onNavigate return value
Assistant
Let me look at the Next.js docs for onNavigate
Assistant
Let me search for more onNavigate docs
Assistant
Let me look at the CI workflow configuration
Assistant
Let me look for the main CI workflow
Assistant
Let me look at the nextjs-deploy-suite workflow
Assistant
Let me look at the deploy suite preparation script
Assistant
Now I have a thorough understanding of the codebase. The
onNavigateimplementation exists in vinext but there are some issues. Let me focus on the key problems:- Pages Router
pendingstate:useLinkStatusdoesn't track pending state in Pages Router mode - The
onNavigateevent shape: vinext addsurlanddefaultPreventedwhich are useful extensions, but the implementation can be improved
Let me also check if there are specific Next.js test scenarios that might fail. Let me look at the e2e deploy script to understand the test setup better.
- Pages Router
Assistant
Let me write a quick test to verify onNavigate fires and run it
Assistant
Now I have a clear understanding. Let me implement the fixes. The key issues are:
useLinkStatusdoesn't track pending state in Pages Router mode- The error handling around
onNavigateis too aggressive (try-catch silently swallows errors)
Let me edit the link.tsx file to fix these issues.
Assistant
Let me look at the exact onNavigate block to understand the code structure
Assistant
Now I'll make the changes. First, let me fix the Pages Router path to track
pendingstate foruseLinkStatus:Assistant
Let me open the file first, then edit
Assistant
Now let me edit the Pages Router path to add pending state tracking:
Assistant
Let me try using the replace command instead
Assistant
Now let me fix the try-catch around
onNavigateto only catch URL parsing errors, not user callback errors:Assistant
Let me goto line 578 first
Assistant
Now let me edit the onNavigate try-catch:
Assistant
Let me try the replace command instead:
Assistant
Let me verify the changes look correct
Assistant
Now let me update the dist file to match. Let me check the dist version of the same section:
Assistant
Let me look at the dist file around line 303 to see the exact code.
Assistant
Now let me update the dist file too. Let me open it and make changes:
Assistant
Now let me update the Pages Router path in the dist file:
Assistant
Now let me run the existing tests to make sure I haven't broken anything
Assistant
Let me verify the dist file changes are complete and correct
Assistant
Let me run the broader test suite to verify nothing is broken
Assistant
Let me review all the changes I made
Assistant
Let me check the dist diff too
Assistant
Let me check if the dist is tracked by git
Assistant
The changes look good. Let me run one final comprehensive test to make sure 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.