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 locate the Link shim, its tests, and the vendored/reference Next.js implementation. Then I’ll reproduce the missing callback with the repository’s existing test setup before making a focused implementation change.
- Assistant
The source already contains an apparent
onNavigateimplementation, so this may be incomplete or behaviorally incompatible rather than wholly absent. I’ll inspect the complete types/click path, repository status, and relevant test conventions to determine what is currently wrong. - Assistant
The shim does invoke the callback, but I need to compare exact eligibility and event semantics. I’ll retrieve the untruncated click handler, inspect the two existing browser tests/fixtures, and locate an installed Next.js source (the expected
.nextjs-refdirectory is absent). - Assistant
The current event incorrectly exposes a non-Next.js
urlfield and wraps callback invocation in a broadtry/catch; however, the reported suite’s “history state replacement via return value” wording may refer to callinghistory.replaceStateinside the callback, not an actual callback return contract. I’ll inspect Next.js 16.2.6’s source map/runtime and upstream test fixture to establish the authoritative API. - Assistant
I found the exact bundled Next.js version. Next’s callback receives only
preventDefault, runs only for client-side-eligible clicks, and does not inspect its return value. I’ll now inspect the whole navigation function and fetch the upstream test source if available through git/network, because its eight cases will reveal the subtle failure behind the already-present implementation. - Assistant
The upstream suite confirms seven scenarios per router. Most already match, but one clear Next.js incompatibility remains: external links with
replacemust calllocation.replace, while this shim always delegates to normal anchor navigation (push). I’ll inspect the upstream fixture and local e2e fixture configuration, then run the closest existing onNavigate tests to reproduce current behavior rather than infer from source alone. - Assistant
The guessed upstream fixture paths were wrong, and the final grep made that combined command exit nonzero. I’ll query the GitHub directory listing for exact fixture names and list Playwright projects/tests locally, then execute only the two closest specs.
- Assistant
Playwright test discovery exceeded the short command timeout, so I’ll avoid full discovery. The upstream fixture has
app,pages, andshareddirectories; I’ll inspect their listings/content and directly run the known local spec files with a larger timeout. - Assistant
The test command did not run because Corepack attempted an interactive pnpm download, which this environment disallows. I’ll use the already-installed local Playwright binary directly. First I’ll inspect
OnNavigate.tsxand nested route files to ensure the implementation handles state persistence and all event cases exactly. - Assistant
The upstream fixture validates that the callback’s synchronous state update survives shared layout/
_appnavigation; the current code should satisfy those internal-link cases. This repository appears to contain a partial prior implementation. I’ll run the local onNavigate e2e cases usingnode_modules/.bin/playwright, then check commit history/blame to distinguish intentional extensions (url) from the missing contract. - Assistant
The browser tests could not launch because Chromium is not installed; importantly, setup rebuilt the package successfully. Git blame shows the callback implementation dates to the initial imported history, explaining the mismatch between the issue report and current tree, while exposing two correctness defects versus Next.js 16.2.6:
- external
replacenavigation is not intercepted withlocation.replace; - callback exceptions are swallowed, unlike Next.js, potentially causing an unintended navigation.
I’ll align these semantics while retaining vinext’s existing
url/defaultPreventedevent extensions used by local compatibility tests. I’ll also simplify prevention tracking so it does not rely on reading a getter after user callback mutation. - external
- Assistant
Python is unavailable, so no source change occurred (the formatter merely checked the unchanged file). I’ll apply the same focused replacements with Node.js and inspect the resulting diff.
- Assistant
The source now matches Next’s callback ordering, prevention semantics, exception propagation, and external replace behavior. Since the browser binary is missing, I’ll look for a DOM test environment already installed and inspect Vitest configuration; if available, I can create a temporary (untracked, then removed) React harness to directly reproduce callback firing/prevention without modifying tests. I’ll also run package type/build checks.
- Assistant
The package build and focused format/lint/type check pass. No root DOM emulator is installed, so direct React click reproduction would require adding a dependency; instead I’ll install the matching Playwright Chromium through the local binary (non-interactive) and rerun the two existing e2e cases. I’ll first inspect generated-file status so only intended source/build artifacts remain.
- Assistant
Chromium installed successfully. I’ll rerun the two existing app/pages onNavigate browser tests now; these exercise callback firing, URL resolution, and client navigation through both router implementations.
- Assistant
Both router-specific onNavigate e2e tests pass. I’ll now run the full Pages Router advanced-link spec (which includes callback
preventDefault, modified/native click behavior, and attributes) plus relevant link unit tests if present. Then I’ll review the final diff/status. - Assistant
All six advanced-link e2e tests pass. I found two focused unit suites and will run them next, followed by final formatting/status/diff checks.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.