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
I’ll inspect the repository’s Link implementation and related navigation tests, then compare the expected
onNavigatecontract with the local shim. I’ll reproduce the current behavior where practical, implement the smallest compatible change, and run the affected tests/type checks. - Assistant
The shim already contains a partial implementation, but it diverges from Next’s behavior in an important way: callback execution and event construction are wrapped in a broad
try/catch, so a URL-construction problem silently turns the callback into a no-op, and callback exceptions are swallowed. I’ll align this path with Next’s contract (invoke exactly once after the click has been accepted, letpreventDefault()cancel navigation, and preserve the URL extension used by this repository’s compatibility tests), and update the ambientnext/linktype accordingly. - Assistant
The source and ambient declarations now agree on the event shape. TypeScript compilation succeeds with the package tsconfig, and the diff is whitespace-clean. The existing unit test runner is not available as a local binary in this checkout; invoking the package runner attempted to download pnpm and timed out, so I verified with the available compiler instead. I’ll submit the focused change.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.