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. The problem is about
<Link onNavigate>prop not being implemented in what seems to be a Next.js compatibility layer (vinext). Let me explore the repository structure first.Assistant
Let me explore more. This seems to be a project that implements Next.js compatibility. Let me look at the packages and find the Link component.
Assistant
Let me look at the vinext package structure.
Assistant
Let me look at the src directory structure.
Assistant
Let me search for the Link component in the source.
Assistant
Let me look at the Link shim and the client navigation files.
Assistant
Let me look at the test file to understand what's failing, and also look at the Next.js reference implementation.
Assistant
Let me search for the test files more broadly.
Assistant
The test files don't exist locally. Let me look at the test structure and also check if there's a
.nextjs-refdirectory for the Next.js reference implementation.Assistant
Let me look at the link test and link navigation test to understand how onNavigate is being tested.
Assistant
Let me look at the test around line 508 and also search for onNavigate in the shims test.
Assistant
Let me search for onNavigate more broadly across all test files to understand the full test coverage.
Assistant
Let me look at the shims.test.ts around line 14701 for the onNavigate tests.
Assistant
Let me check the e2e tests for onNavigate and the fixture pages.
Assistant
Let me look at the fixture files to see how onNavigate is used.
Assistant
Now let me look at the pages-basic fixture.
Assistant
Let me look at the full link.tsx file. I noticed earlier it says "171 more lines truncated" so let me view the rest.
Assistant
Let me see the full file now.
Assistant
Let me check if there's a
.nextjs-refdirectory for the Next.js reference.Assistant
Let me run the relevant tests to see what's failing.
Assistant
Let me check how to run tests and look at the package.json.
Assistant
Let me look at the vitest configuration.
Assistant
Let me look for the test configuration.
Assistant
Let me look at the test config in full.
Assistant
Let me run the onNavigate tests from the shims test file.
Assistant
Let me check the dist version of the link shim.
Assistant
Let me compare the source and dist for onNavigate.
Assistant
Let me look at the dist file around those lines.
Assistant
Let me look at navigateClientSide to understand its signature.
Assistant
Let me look at the navigateClientSide function signature more closely.
Assistant
Let me search for the Next.js link implementation in node_modules for reference.
Assistant
Let me check if there's an e2e test directory for link-on-navigate.
Assistant
Let me look at the e2e test for onNavigate in the pages-router suite.
Assistant
Let me look at the e2e test for onNavigate in the app-router suite.
Assistant
Let me create a minimal reproduction script to test if onNavigate fires.
Assistant
Let me look at this from a different angle. Let me check what the actual Next.js link component expects for onNavigate, by looking at the Next.js API docs or source patterns.
Assistant
Let me look at the next-shims.d.ts file for the Link type.
Assistant
Let me look at the dist/link.js around the onNavigate implementation.
Assistant
Let me look at git log for recent changes related to onNavigate.
Assistant
Let me look at commits related to onNavigate or NavigateEvent.
Assistant
Let me check if the dist is up to date by comparing the dist and source.
Assistant
Let me try running just the onNavigate specific tests in a targeted way.
Assistant
Let me try a faster approach - run the specific link-navigation test with grep for the test name.
Assistant
Let me write a minimal test script that tests onNavigate in isolation.
Assistant
Let me compare the source and dist more carefully for the handleClick function.
Assistant
Let me search for references to Next.js test suites or link-on-navigate.
Assistant
Let me look at the Next.js link type definitions to understand the full onNavigate API.
Assistant
Let me look at the Next.js link documentation for onNavigate.
Assistant
Let me look at the Next.js link implementation.
Assistant
Let me look at the Next.js app-dir/link.js for the onNavigate implementation.
Assistant
Let me look at the full linkClicked function in Next.js.
Assistant
Let me also check the client/link.js for comparison.
Assistant
Let me search for the Next.js e2e test for onNavigate in the node_modules.
Assistant
Let me look at how the Next.js Deploy Suite works and what tests are failing.
Assistant
Let me look at the nextjs-compat test directory.
Assistant
Let me check the navigation.test.ts in nextjs-compat.
Assistant
Let me look for any test references in the Next.js node_modules.
Assistant
Let me look at the deploy suite script.
Assistant
Let me search the TRACKING.md for link-on-navigate.
Assistant
Let me look for the link-on-navigate-prop test in the Next.js distribution.
Assistant
Let me examine how the existing Link tests are structured.
Assistant
Let me look at the download link test in link-navigation that already tests onNavigate.
Assistant
Let me look at the mock setup.
Assistant
Let me look at the mock setup.
Assistant
Let me create a minimal test to verify if onNavigate fires.
Assistant
Let me try to run this test directly with vitest.
Assistant
Let me try a simpler script that directly tests the Link dist module.
Assistant
Let me look at the Next.js link documentation examples for onNavigate.
Assistant
Let me search for TODO/FIXME/hack related to onNavigate.
Assistant
Let me check if the dist is up to date with the source.
Assistant
Let me look at how
next/linkis resolved in vinext.Assistant
Let me look at the vinext package.json.
Assistant
Let me search for how next/link is aliased to vinext.
Assistant
Let me look at the next-shims.d.ts more fully.
Assistant
Let me look at the onNavigate tests in shims.test.ts more carefully.
Assistant
Let me look at the toBrowserNavigationHref function.
Assistant
Let me look at that function.
Assistant
Let me compare the source and dist handleClick functions more carefully.
Assistant
Let me look at the view-transitions example that uses onNavigate.
Assistant
Let me look at how vinext resolves next/link in the build.
Assistant
Let me look at the Next.js link.js source more carefully for return value usage.
Assistant
Let me look at the Next.js link.d.ts for the OnNavigateEventHandler type.
Assistant
Let me look at the AGENTS.md file for context about this issue.
Assistant
Let me look at the full linkClicked function in Next.js app-dir/link.js.
Assistant
Let me look at the LinkComponent onClick handler in Next.js app-dir/link.js.
Assistant
Let me look at the Next.js client/link.js for onNavigate implementation to compare with vinext's Pages Router path.
Assistant
Let me write a real reproduction test that can run quickly.
Assistant
Let me look at the useLinkStatus implementation more carefully and compare with Next.js.
Assistant
Let me look at the Next.js useLinkStatus implementation.
Assistant
Let me look at the deploy suite script and understand how vinext is deployed for Next.js tests.
Assistant
Let me check when the onNavigate implementation was added to the codebase.
Assistant
Let me search git log for onNavigate.
Assistant
Let me look at the commit that fixed onNavigate URL resolution.
Assistant
Let me look at the diff from this commit.
Assistant
Let me look at the links module that manages link instance status.
Assistant
Let me look at the full client/link.js for the Pages Router implementation of onNavigate.
Assistant
Now I have a thorough understanding of the codebase. Let me look at what specific changes are needed. The onNavigate implementation exists but may have subtle issues. Let me check the exact behavior by looking at the handleClick function flow once more and comparing critical paths.
Assistant
Let me write a simpler node-based test that directly uses the dist module to check onNavigate behavior.
Assistant
Let me look at the Actual Next.js link.d.ts types to compare with vinext's next-shims.d.ts.
Assistant
Let me look at the shims.test.ts for any tests that actually render and click a Link with onNavigate.
Assistant
Let me verify the Next.js version.
Assistant
Let me check if vinext supports the
transitionTypesprop.Assistant
Let me check if vinext supports the legacyBehavior prop.
Assistant
Let me check the dist file for the useLinkStatus export.
Assistant
Let me do a final verification of the onNavigate implementation in the dist file.
Assistant
Now I'll make the necessary changes. Based on my thorough analysis, the
onNavigateimplementation exists but needs to be aligned more closely with Next.js. Let me start by updating the type definitions.Assistant
Let me open the file properly.
Assistant
The
opencommand seems to be trying to execute the file. Let me try with just the filename.Assistant
Let me try the open command with proper syntax.
Assistant
Let me look at the full context of the next-shims.d.ts Link module declaration to update it properly.
Assistant
Now let me update the
next-shims.d.tsto properly type the onNavigate event, matching the actual implementation.Assistant
Let me use the replace command to update the type definition.
Assistant
Let me use sed to update the file.
Assistant
Let me check if there are any uncommitted changes or if the dist needs rebuilding.
Assistant
Let me re-read the Next.js docs for onNavigate to understand any return value behavior.
Assistant
Let me look at the dist file around the handleClick function for variable scoping issues.
Assistant
Let me check the dist file for any potential issues with async/await.
Assistant
Let me check the syntax differently.
Assistant
Let me check the syntax using acorn or just verifying the file is valid JavaScript.
Assistant
Let me check when the onNavigate code was last changed in link.tsx.
Assistant
Let me look at what the last commit to link.tsx changed.
Assistant
Now I'll make the necessary changes. Let me update both the source and dist files to ensure onNavigate works correctly. First, let me remove the try/catch that silently swallows errors.
Assistant
Let me update the source file to remove the try/catch around onNavigate, matching Next.js behavior more closely.
Assistant
Let me use node to make the change.
Assistant
Let me write a script to a file and run it.
Assistant
Let me fix the remaining issue - the
} catchpart is still there.Assistant
Let me look at the current state around line 597.
Assistant
Let me fix the indentation and remove the remaining catch block.
Assistant
Let me verify the fix looks correct.
Assistant
Now let me update the dist file to match.
Assistant
Let me fix the dist file as well.
Assistant
Let me update the dist file.
Assistant
Now let me fix the "Click state tracking broken" issue. Looking at the code,
setPending(true)is only called for App Router, not for Pages Router. Let me fix this.Assistant
Let me fix the click state tracking by setting pending for both App Router and Pages Router paths.
Assistant
Now let me apply the same fix to the dist file.
Assistant
Let me update the dist file for the Pages Router path.
Assistant
Let me verify all changes and check git diff.
Assistant
Let me check if the dist changes are tracked.
Assistant
Let me check if the dist files are tracked by git.
Assistant
Let me verify the source file compiles correctly by checking for any syntax issues.
Assistant
Let me verify the dist file changes are correct.
Assistant
Let me check the rest of the dist file to ensure proper closing.
Assistant
Let me also check if there's something with the
transitionTypesprop that might relate to onNavigate.Assistant
Let me do a final check to make sure the e2e fixtures that use onNavigate are still compatible with my changes.
Assistant
Let me do the final review of all changes.
Assistant
Let me also verify the dist file syntax is valid.
Assistant
I've made the following changes:
-
Removed
try/catcharoundonNavigatein both source and dist: This aligns with Next.js behavior and prevents silent error swallowing that could hide issues whereonNavigatedoesn't fire. -
Added
setPending(true)for Pages Router navigation: Previously,useLinkStatus().pendingwould stayfalsefor Pages Router links even during navigation. Now it properly tracks pending state for both App Router and Pages Router. -
Added
finallyblock for Pages Router: EnsuressetPending(false)is called even if navigation fails, preventing the link from getting stuck in pending state. -
Updated
next-shims.d.ts: ChangedpreventDefault()method syntax topreventDefault: () => voidproperty syntax to match Next.js's type definition exactly.
Let me submit these changes.Let me now submit the changes.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.