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 structure and the
next/linkimplementation first, then trace its click/navigation event flow and existing tests. I’ll reproduce the missing callback behavior with the project’s available test tooling, implement the smallest compatible change, run focused and broader relevant tests, and review the final diff before submitting. - Assistant
The source already contains an
onNavigateimplementation and dedicated tests, so this checkout appears to include a partial or recently attempted fix rather than the reported baseline. I’ll inspect the implementation, its event type, router dispatch, and test history/status to determine whether the remaining bug is that the callback is invoked at the wrong point or that cancellation/history semantics are incomplete. - Assistant
Next.js’s reference confirms the contract:
onNavigateruns only after a same-origin client-navigation click, receives an event whose meaningful API ispreventDefault(), and navigation is skipped when it is called. It does not use a callback return value or perform history replacement itself. Vinext’s code mostly matches this, but its current event construction is wrapped in a broadtry/catch, and the public declaration is narrower/inconsistent. I’ll run the focused unit tests and inspect the actual issue-specific fixture availability, then make the implementation align more exactly and ensure both router modes invoke the callback before navigation. - Assistant
The combined test command exceeded the terminal time limit before producing usable results, so I’ll split validation into focused commands. Before editing, I’ll also check the repository’s current diff and build/type-check behavior; the source appears to have an existing implementation, so I want the change to target a concrete compatibility gap rather than duplicate it.
- Assistant
The focused investigation found the concrete defect: the callback invocation is inside a broad
try/catch, so any exception while constructing the event—or an exception thrown by the user callback—is swallowed and the link proceeds with navigation. That diverges from Next.js and can make callback-based state/history handling appear ineffective. I’ll remove that swallowing behavior, construct the URL from the already-normalized browser target, and keeppreventDefault()as the sole cancellation mechanism. I’ll also correct the prop’s compatibility comment. - Assistant
The edit helper failed because this environment has no
pythonexecutable; no files were changed. I’ll apply the same targeted replacement using Node (already required by this TypeScript/JavaScript repository), then inspect the diff. - Assistant
The implementation now matches Next.js’s ordering and cancellation behavior, while preserving Vinext’s useful
event.urlextension. I’ll verify type correctness and run the smallest available tests with explicit shell timeouts; the earlier Vitest invocation appears to hang during project startup, so I’ll report whether that is an environment limitation rather than treat it as a code failure. - Assistant
Validation is partially blocked by the checkout: Corepack tries to download pnpm interactively, and the root TypeScript check has 20 pre-existing unrelated workspace errors (plus no local Vitest binary). The changed file itself introduced no reported TypeScript error. I’ll perform a final static review, use the repository’s existing built shim only as a reference (not modify generated files), and ensure the diff is minimal and clean before submission.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.