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.
Interface
No new interfaces are introduced.
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 call ) using or 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
Port is 4174, not 4173. Let me fix the spec's BASE.
Assistant
Now let's rerun the debug test with the console.log now present in dist.
Assistant
Now rebuild and rerun the debug test.
Assistant
Let's update our debug test to wait for hydration before clicking.
Assistant
Let's fetch every fixture file.
Assistant
Now let's write a Playwright spec exercising these scenarios (mirroring the real Next.js test but adapted, using simple clicks instead of the Next.js test harness's
elementByIdhelper).Assistant
Now let's revert the debug console.log from link.tsx before rebuilding, then run the full spec.
Assistant
Now let's rebuild and re-run the full temp spec plus existing relevant tests.
Assistant
All 7 App Router scenarios pass. Now let's verify Pages Router too, since the real test suite covers both.
Assistant
All 7 scenarios now pass for both App Router and Pages Router. Now let's clean up the temporary test fixtures and restore
_app.tsx, then run the existing test suites to make sure nothing broke.Assistant
Good, all temporary files cleaned up; only the real source change remains. Let's rebuild the package (dist) since the postinstall build step and CI likely rebuild dist from src, but let's check whether
dist/is committed to the repo.Assistant
dist is gitignored, so no need to commit it. Now let's rebuild once more (already done) and run the broader existing test suites to check nothing regressed.
Assistant
All unit tests pass (4485 passed, 2 skipped). Now let's run the relevant e2e Playwright specs for Link/navigation to make sure nothing regressed.
Assistant
Now the app-router navigation test and broader app-router suite.
Assistant
All pass. Let's also run broader link-related tests in the vitest suite (link-navigation.test.ts) and the full app-router e2e suite for a broader regression check (at least the "advanced" and "navigation" specs).
Assistant
Let's run lint/check to ensure code style compliance.
Assistant
Lint and formatting pass. Let's also run
vp checkfor type-checking.Assistant
Everything passes. Let's do a final review of the diff and ensure the repository is clean (no leftover temp files).
Assistant
This is the final change. Let me go through the checklist:
- Reproduced the error: Yes. I fetched the actual Next.js v16.2.6
test/e2e/link-on-navigate-propsuite (test file + fixtures) from the real Next.js repo, ported it into vinext's own fixtures/e2e specs temporarily, and confirmed that 6/7 scenarios already passed, but the "external link withreplaceprop should keep history length unchanged" scenario failed — clicking an external (cross-origin)<Link replace>pushed a new history entry instead of replacing it, exactly matching the class of "History state replacement... not working" failures mentioned in the issue. - : Yes. After adding the fallback (mirroring real Next.js's behavior for non-local URLs with ), all 7 scenarios passed for both the App Router and Pages Router variants of the fixture.
- Reproduced the error: Yes. I fetched the actual Next.js v16.2.6
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.