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 first inspect the repository structure and locate both the Link shim and relevant tests/reference implementation. Then I’ll reproduce the missing callback, implement the contract, and run focused plus broader tests.
- Assistant
The source already contains an
onNavigateblock, suggesting either a partial implementation or pre-existing uncommitted work. I’ll inspect Git state, the complete click path, focused Link tests, and any vendored Next.js reference to determine why the callback contract still fails. - Assistant
Git is clean, so this is the repository baseline rather than uncommitted work. The current implementation diverges from Next.js by adding
url/defaultPrevented, swallowing callback exceptions, and invoking only aftere.preventDefault(). I’ll locate click-oriented tests and inspect the installed Next package/source or upstream history to pin down exact Next 15/16 behavior, including whether any callback return value is meaningful. - Assistant
The exact Next.js 16.2.6 source is embedded in its source map. I’ll extract the relevant helper and event typing, compare both Pages and App Router variants, and identify the commit that introduced vinext’s current partial block.
- Assistant
The public type confirms the callback receives only
{ preventDefault }and returnsvoid; the issue’s “return value” wording likely means effects performed inside the callback (such ashistory.replaceState), not a special return protocol. I’ll extract the source with Node to verify exact ordering and filtering, then reproduce behavior through the existing browser fixture—particularly whether vinext’s navigation races/overwrites callback history changes. - Assistant
There is already a fixture that depends on vinext’s nonstandard
event.url, but no focused callback contract test. I’ll avoid altering tests per instructions and use the source map directly without extra dependencies, then inspect the upstream eight-test suite from the installed Next package if available. - Assistant
The path glob was too restrictive because pnpm encodes peer versions in the directory name. I’ll pass the known map path via a shell wildcard and extract the source now.
- Assistant
The current click block largely follows upstream and should fire for normal local clicks. To reproduce the reported eight scenarios accurately, I’ll fetch/read the exact Next.js test fixture from the pinned v16.2.6 tag (network permitting). This should reveal the discrepancy hidden by vinext’s current minimal fixture.
- Assistant
The upstream suite verifies seven behaviors per router (14 total): normal internal callback, cancellation, and suppression for modified/external/target/download clicks, plus external
replace. The current code appears to satisfy these in isolation, so I’ll inspect the shared test component and vinext’s module alias/client-boundary handling. A likely cause is thatnext/linkresolves through a wrapper that omitsonNavigate, rather than the click code itself. - Assistant
The guessed fixture filenames were wrong. I’ll query the GitHub API recursively for the exact paths, then inspect those files. I’ll also inspect the RSC exclusion mechanism to ensure the Link shim is consistently treated as a client module.
- Assistant
The alias and client-module exclusion look correct. I’ll inspect the exact shared component and then run the Next suite against vinext using the repository’s deploy-suite tooling if available; otherwise I’ll create a temporary equivalent fixture/script and remove it afterward.
- Assistant
A dedicated port already exists in
tests/link-navigation.test.ts, which is the correct reproduction target. I’ll inspect and run that suite before changing anything; this will establish which scenario currently fails in the repository’s own harness. - Assistant
The test command hit Corepack’s interactive package-manager download prompt, not a code failure. I’ll invoke the checked-in
vpbinary directly and inspect the remainder of the file around allonNavigateassertions. - Assistant
The focused suite passes but only covers download suppression; it does not test a successful callback or cancellation. Comparing directly to Next reveals two concrete compatibility gaps: vinext wraps callback invocation in a
try/catch(so errors or URL construction failures silently skip behavior), and external links withreplacedo not calllocation.replace, failing the upstream history test. I’ll check whether the nonstandardevent.urlis relied on elsewhere, then refactor invocation to be unconditional and synchronous while preserving compatibility if needed, and implement external replacement. - Assistant
Vinext intentionally extends the event with
url, and existing tests rely on it, so I’ll preserve that extension while fixing semantics: construct the URL before invocation, never swallow callback exceptions, invoke exactly once for eligible local navigation, honorpreventDefault, and uselocation.replacefor externalreplacelinks as Next does. I’ll also inspect existing shims assertions to ensure the refactor matches their harness. - Assistant
I’ll now apply the source fix. The external path will mirror Next’s special
replacebehavior, while localonNavigatewill no longer be conditionally skipped or have exceptions suppressed. Cancellation remains based onevent.preventDefault(), since Next’s declared callback return type isvoidand upstream ignores return values. - Assistant
The line-number edit exposed two issues on review: it accidentally removed the
scrollandlocaleprop declarations, and the replaced click range left duplicate old lines. I’ll correct both immediately, then replace the callback block cleanly. - Assistant
The prop declarations are restored. I’ll remove the duplicate branch and install the corrected callback block using the now-confirmed line numbers.
- Assistant
The diff is now clean and matches upstream ordering. I’ll validate with the focused Link navigation suite, the broader Link/shims suites, type checking, formatting, and package build. This also confirms that preserving vinext’s
url/defaultPreventedextension does not regress existing behavior. - Assistant
All 1,042 relevant tests passed, full static checks passed, formatting passed, and the package built successfully (only the repository’s expected virtual-module warnings). I’ll now inspect final Git state and built output, and perform a concise final review against each upstream edge case before submitting.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.