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
Let me start by exploring the repository structure to understand what we're working with.
Assistant
Let me explore the structure more, specifically looking for the Link component and related files. Let me first check the packages directory since this is likely a monorepo.
<tool_call> <function=bash_terminal> <parameter=command> find packages -name ".ts" -o -name ".tsx" | head -50 </tool_call>
Assistant
Let me run the command properly to find TypeScript files in the packages directory.
Assistant
Let me search for files related to "link" more specifically, since the issue is about the Link component.
<tool_call> <function=bash_terminal> <parameter=command> find packages -type f ( -name ".ts" -o -name ".tsx" ) | xargs grep -l "Link" 2>/dev/null | head -20 </tool_call>
Assistant
Let me use grep to find files containing "Link" in the packages directory.
Assistant
Good, I can see there's a
packages/vinext/dist/shims/link.d.tsfile which is likely the shim for the Link component. Let me explore the source structure first to find the actual source files (not the dist).<tool_call> <function=bash_terminal> <parameter=command> ls -la packages/ </tool_call>
Assistant
Let me use a proper bash command to list the packages directory.
Assistant
There's only one package called vinext. Let me look at its structure more closely.
<tool_call> <function=bash_terminal> <parameter=command> ls -la packages/vinext/ </tool_call>
Assistant
Let me use the bash_terminal tool to list the packages/vinext directory.
Assistant
Good, I can see there's a
srcdirectory. Let me explore that to find the Link-related source files.Assistant
Good, I see there's a
shimsdirectory. Let me look at that since the issue mentions the Link component shim.Assistant
Now let me look at the link.tsx file to understand the current implementation:
Assistant
Now let me see the test file mentioned in the issue to understand what's expected:
<tool_call> <function=bash_terminal> <parameter=command> find tests -name "link-on-navigate" -type f 2>/dev/null </tool_call>
Assistant
Let me run the command properly to find the link-on-navigate test file.
Assistant
Let me search for the link-on-navigate test in a different way:
Assistant
I found the test files. Let me examine the link-navigation.test.ts file to understand what tests are related to onNavigate.
Assistant
This file doesn't seem to have tests specifically for
onNavigate. Let me search more specifically for onNavigate tests:<tool_call> <function=bash_terminal> <parameter=command> grep -n "onNavigate" tests/*.ts 2>/dev/null </tool_call>
Assistant
Let me run the grep command properly to search for onNavigate in test files.
Assistant
Let me look at the shims.test.ts file to see the onNavigate tests:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '14700,14900p' tests/shims.test.ts </tool_call>
Assistant
Let me run the sed command to see the onNavigate tests in shims.test.ts.
Assistant
I see there's a test file with tests for the
onNavigatefunctionality, but these tests only test the NavigateEvent interface, not the actual Link component integration. Let me also check the link-navigation.test.ts file to see more tests related to onNavigate:<tool_call> <function=bash_terminal> <parameter=command> sed -n '500,600p' tests/link-navigation.test.ts </tool_call>
Assistant
Let me run the sed command to see the relevant portion of link-navigation.test.ts that contains onNavigate tests.
Assistant
Now let me look at the existing code more carefully. The issue is that the
onNavigateprop is not being implemented. Looking at the link.tsx file I already saw, I can see that:- The
onNavigateprop is defined in theLinkPropsinterface - The
onNavigatecallback is called in thehandleClickfunction - The NavigateEvent interface is already defined
Let me look more carefully at the handleClick function in the link.tsx file to see how it handles onNavigate:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '330,450p' packages/vinext/src/shims/link.tsx </tool_call>
- The
Assistant
Let me run the sed command properly to see the handleClick function in the link.tsx file.
Assistant
I see that the code includes
onNavigatein the destructured props. Now let me find the handleClick function to see the implementation of the onNavigate callback:<tool_call> <function=bash_terminal> <parameter=command> sed -n '530,650p' packages/vinext/src/shims/link.tsx </tool_call>
Assistant
Let me run the sed command properly to find the handleClick function.
Assistant
Now let me look at the handleClick function implementation:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '538,680p' packages/vinext/src/shims/link.tsx </tool_call>
Assistant
Let me run the sed command properly to get the handleClick function content.
Assistant
Now I understand the code. The
onNavigatecallback is already implemented in the handleClick function (lines 577-593). The code:- Creates a
NavigateEventobject with theurlandpreventDefault()method - Calls
onNavigate(navEvent) - Checks if
preventDefault()was called and skips navigation if so
However, looking at the issue description, it says:
onNavigatecallback never fires on click- Click state tracking broken (link thinks it was never clicked)
- History state replacement via
onNavigatereturn value not working
Looking at the test case in link-navigation.test.ts around line 508-540, there's a test that:
- Uses a Link with
download: trueandonNavigate - Expects
onNavigateNOT to be called because the link has thedownloadattribute
This test expects that
onNavigateis not called when the link has adownloadattribute (because download links should not be intercepted).Let me look at the test more carefully to understand what's being tested:
- Creates a
Assistant
Let me run the sed command properly to see the full test that involves onNavigate.
Assistant
This test verifies that
onNavigateis NOT called when a link hasdownload: trueattribute. That's expected behavior.But the issue mentions 8 failures in test/e2e/link-on-navigate-prop/index.test.ts. Let me look at that test file if it exists in the repository:
<tool_call> <function=bash_terminal> <parameter=command> find . -path "link-on-navigate" 2>/dev/null | head -20 </tool_call>
Assistant
Let me search for link-on-navigate test files in the repository.
Assistant
Let me run a broader search for the test file:
Assistant
Now let me run the existing tests related to link and onNavigate to see what's failing:
<tool_call> <function=bash_terminal> <parameter=command> cd /vinext && npm test -- tests/link-navigation.test.ts 2>&1 | head -100 </tool_call>
Assistant
Let me run the test command properly.
Assistant
The tests pass. Let me also run the shims tests to check if the onNavigate tests pass:
<tool_call> <function=bash_terminal> <parameter=command> cd /vinext && npm test -- tests/shims.test.ts -t "onNavigate" 2>&1 | head -100 </tool_call>
Assistant
Let me run the test command properly to test the onNavigate functionality.
Assistant
The tests are passing for onNavigate. However, the issue mentions that in the Next.js Deploy Suite (vinext's CI), there are 8 failures. Let me check if there's a specific test file for onNavigate that should exist but doesn't. Let me also look at the Next.js implementation to understand what the expected behavior should be.
Let me check if there's any reference to Next.js implementation or if I can find more about what the expected behavior should be:
<tool_call> <function=bash_terminal> <parameter=command> grep -r "onNavigate" packages/vinext/src/ 2>/dev/null </tool_call>
Assistant
Let me run the grep command properly to search for onNavigate in the source code.
Assistant
I see the
onNavigateprop is defined and used. Let me look at the next-shims.d.ts file to see the interface there:Assistant
Now I see the issue! In the
next-shims.d.tsfile, theonNavigatetype is defined as:typescriptonNavigate?: (event: { preventDefault(): void }) => void;But in the actual implementation in
link.tsx, theNavigateEventinterface is defined as:typescripttype NavigateEvent = { url: URL; /** Call to prevent the Link's default navigation (e.g. for View Transitions). */ preventDefault(): void; /** Whether preventDefault() has been called. */ defaultPrevented: boolean; };And the prop type in
link.tsxis:typescriptonNavigate?: (event: NavigateEvent) => void;Assistant
The issue mentions looking at
.nextjs-ref/packages/next/src/client/link.tsxfor the Next.js implementation. Let me check if this exists:Assistant
The .nextjs-ref directory doesn't exist. Let me look at the Next.js GitHub repository to understand the expected behavior. Let me first look at what the current tests are expecting and see if the current implementation is correct or not.
Let me look more closely at the implementation in link.tsx to see if there might be a bug:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '570,600p' packages/vinext/src/shims/link.tsx </tool_call>
Assistant
Let me search for the onNavigate callback implementation in the link.tsx file to see how it's being called.
Assistant
Let me look at the specific lines around 578-595 to see the full implementation of the onNavigate callback:
Assistant
Assistant
Let me run the curl command properly to fetch the Next.js implementation.
Assistant
Let me fetch more of the Next.js link.tsx to see the onNavigate implementation:
Assistant
Now I see the key difference! In Next.js, the
OnNavigateEventHandleris defined as:typescripttype OnNavigateEventHandler = (event: { preventDefault: () => void }) => voidThis only has
preventDefault()- it does NOT have theurlanddefaultPreventedproperties that vinext has defined!So the vinext implementation is adding extra properties (
urlanddefaultPrevented) that Next.js doesn't have. But this shouldn't break the callback from firing.Let me look at how Next.js handles the navigation in their link.tsx:
<tool_call> <function=bash_terminal> <parameter=command> curl -s "https://raw.githubusercontent.com/vercel/next.js/canary/packages/next/src/client/link.tsx" 2>/dev/null | grep -B5 -A100 "function handleClick" | head -150 </tool_call>
Assistant
Let me search for the handleClick function in the Next.js implementation to understand how they call onNavigate.
Assistant
The command returned no output. Let me search differently for the onNavigate callback invocation in Next.js.
<tool_call> <function=bash_terminal> <parameter=command> curl -s "https://raw.githubusercontent.com/vercel/next.js/canary/packages/next/src/client/link.tsx" 2>/dev/null | grep -n "onNavigate" | head -10 </tool_call>
Assistant
Let me try fetching the file and searching for the onNavigate implementation in Next.js:
Assistant
Now let me look at the specific lines around 255-265 where onNavigate is called:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '240,280p' /tmp/next_link.tsx </tool_call>
Assistant
Let me run the sed command properly to see the Next.js onNavigate implementation.
Assistant
Now I understand the Next.js implementation! Looking at lines 253-270:
e.preventDefault()is called first (line 252)- Then, if
onNavigateis provided, it's called (line 255) - If the callback calls
preventDefault(), navigation is skipped (line 263-266)
This is exactly what vinext does. So the implementation looks correct.
Wait, let me look at line 246 -
e.preventDefault()is called unconditionally for non-local URLs. Let me see the full context:Assistant
Now I see the key issue! In Next.js, the
onNavigatecallback is called INSIDE thenavigate()function (lines 255-267), but thenavigate()function is never called directly in the code I saw. Let me look for wherenavigate()is called.Wait, looking at the code more carefully, I see that in Next.js:
linkClickedis called when a link is clickede.preventDefault()is callednavigate()function is defined but never invoked in the code I saw
Let me search for where
navigate()is called:Assistant
I see! On line 283,
navigate()is called unconditionally after the function definition. This means the order is:e.preventDefault()is called firstnavigate()is called- Inside
navigate(),onNavigatecallback is called
Now let me look at how the link is rendered and how
linkClickedis called:<tool_call> <function=bash_terminal> <parameter=command> sed -n '350,500p' /tmp/next_link.tsx </tool_call>
Assistant
Let me run the sed command to see where the onClick handler is defined in Next.js's Link component.
Assistant
Let me continue to search for where onClick is handled:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '500,600p' /tmp/next_link.tsx </tool_call>
Assistant
Let me continue to find the onClick handler implementation in Next.js's Link component.
Assistant
Let me continue to see how onClick is handled in Next.js's Link component:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '600,680p' /tmp/next_link.tsx </tool_call>
Assistant
Let me continue reading the onClick handler in Next.js to understand how they call linkClicked.
Assistant
Now I understand! In Next.js's implementation:
- When a link is clicked, the
onClickhandler is called (line 605-618) - First, it calls
onClick(e)if provided - Then, it checks
if (e.defaultPrevented)- if the user prevented default in onClick, navigation is skipped - Then it calls
linkClicked(...)which:- Checks for download attribute or modified event
- Calls
e.preventDefault() - Calls
onNavigatecallback - Navigates if preventDefault wasn't called by onNavigate
Now let me compare this with vinext's implementation to see if there's a bug. Let me look at vinext's handleClick again:
- When a link is clicked, the
Assistant
I see the vinext implementation now. Comparing with Next.js, the vinext implementation looks correct. The order is:
- Call
onClick(e)(line 539) - Check if
e.defaultPrevented(line 540) - Check for download attribute (line 542-544)
- Check for modifier keys (line 546-548)
- Check for target attribute (line 550-552)
- Handle external links (lines 554-560)
- Call
e.preventDefault()(line 562) - Call
onNavigatecallback (lines 578-595) - If preventDefault was called, return (lines 595-597)
- Call
Assistant
Let me run the tests more specifically for the shims.test.ts file that contains the onNavigate tests:
Assistant
The onNavigate tests pass. Let me now look at the issue description more carefully. The issue mentions 8 failures in test/e2e/link-on-navigate-prop/index.test.ts from the Next.js Deploy Suite. These tests are from the Next.js repository, not vinext.
Let me search for the actual test file to understand what it's testing:
Assistant
Now I understand the tests! These are E2E tests that check:
onNavigateis triggered along withonClickfor internal navigationonNavigateis NOT triggered when using modifier keysonNavigateshould be called BEFORE navigation (allowing preventDefault to work)onNavigateshould NOT be triggered for external links with target="_blank"onNavigateshould NOT be triggered for download linksonNavigateshould NOT be triggered for external links (without target)- History state replacement with
replaceprop should work
Let me also check the test page to understand the setup:
<tool_call> <function=bash_terminal> <parameter=command> curl -s "https://raw.githubusercontent.com/vercel/next.js/canary/test/e2e/link-on-navigate-prop/app-router/page.tsx" 2>&1 | head -150 </tool_call>
Assistant
Let me try the curl command properly to get the test page source.
Assistant
The path might be different. Let me try to find the test page directory structure:
<tool_call> <function=bash_terminal> <parameter=command> curl -s "https://raw.githubusercontent.com/vercel/next.js/canary/test/e2e/link-on-navigate-prop/app-router/page.tsx" 2>&1 || curl -s "https://api.github.com/repos/vercel/next.js/contents/test/e2e/link-on-navigate-prop" 2>&1 | head -50 </tool_call>
Assistant
Let me try to find the test page structure:
Assistant
Let me look at the app directory to find the page source:
<tool_call> <function=bash_terminal> <parameter=command> curl -s "https://api.github.com/repos/vercel/next.js/contents/test/e2e/link-on-navigate-prop/app" 2>&1 | head -50 </tool_call>
Assistant
Let me use the bash_terminal to run the curl command properly.
Assistant
Let me look at the app-router directory to find the page source:
<tool_call> <function=bash_terminal> <parameter=command> curl -s "https://raw.githubusercontent.com/vercel/next.js/canary/test/e2e/link-on-navigate-prop/app/app-router/page.tsx" 2>&1 </tool_call>
Assistant
Let me run the curl command properly to fetch the page source.
Assistant
The page.tsx file is very simple. Let me look at the shared directory for the link component that's used in the tests:
<tool_call> <function=bash_terminal> <parameter=command> curl -s "https://api.github.com/repos/vercel/next.js/contents/test/e2e/link-on-navigate-prop/shared" 2>&1 </tool_call>
Assistant
Let me run the curl command to get the shared directory contents.
Assistant
Now let me get the OnNavigate.tsx file which is the test component:
Assistant
Assistant
Let me run the sed command to see the external link handling code in vinext.
Assistant
I found the issue! The vinext implementation doesn't handle the
replaceprop for external links. Looking at the Next.js implementation:javascriptif (!isLocalURL(href)) { if (replace) { e.preventDefault() location.replace(href) } return }But in vinext, the code just returns early for external links without handling
replace:typescriptif (isAbsoluteOrProtocolRelativeUrl(resolvedHref)) { const localPath = toSameOriginAppPath(resolvedHref, __basePath); if (localPath == null) return; // truly external navigateHref = localPath; }The fix needs to add the
replacehandling for external links. Let me now implement the fix:Assistant
Now I understand the issue. The vinext implementation doesn't handle the
replaceprop for external links. Let me fix this:Assistant
Now I need to fix the external link handling to support the
replaceprop. Let me update the code:Assistant
Let me verify the changes were applied correctly:
Assistant
I see the sed command duplicated the code instead of replacing it. Let me fix this properly by restoring and then making the correct changes:
Assistant
Good, I've restored the original file. Now let me make the correct fix by modifying the external link handling section. First, let me see the original code again:
Assistant
Now let me use the edit command to properly replace the external link handling section with the fixed version:
Assistant
Let me first open the file and then edit it:
Assistant
Now let me find the exact line numbers for the external link handling code and use the edit command properly:
Assistant
Let me use the edit command to properly fix the external link handling:
<tool_call> <function=edit> <parameter=LINE_RANGE> 557:564 <parameter=REPLACEMENT_TEXT> // External links: let the browser handle it. // Same-origin absolute URLs (e.g. http://localhost:3000/about) are // normalized to local paths so they get client-side navigation. if (isAbsoluteOrProtocolRelativeUrl(resolvedHref)) { const localPath = toSameOriginAppPath(resolvedHref, __basePath); if (localPath == null) { // Truly external link if (replace) { e.preventDefault(); location.replace(resolvedHref); } return; } navigateHref = localPath; } else { navigateHref = normalizedHref; } </tool_call>
Assistant
The edit command requires the file to be open, and it looks like the file is already open. Let me check the current state and try the edit command again.
Assistant
I see there's an extra closing brace at line 574. Let me fix this:
Assistant
Let me try a different approach to delete the extra closing brace at line 574.
Assistant
Let me verify the changes are correct now:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '555,595p' /vinext/packages/vinext/src/shims/link.tsx </tool_call>
Assistant
Let me run the sed command to verify the changes.
Assistant
The external link handling now correctly handles the
replaceprop. Now let me run the tests to verify that the changes work correctly:<tool_call> <function=bash_terminal> <parameter=command> cd /vinext && npm test -- tests/link-navigation.test.ts 2>&1 | tail -30 </tool_call>
Assistant
Let me run the tests properly.
Assistant
I see the issue - I need to properly define
navigateHreffor all cases. Let me fix the code:Assistant
The issue is that I removed the original
let navigateHref = normalizedHref;line. The code should work, but let me check if there's a scoping issue. Let me look at the full handleClick function to understand the context better:Assistant
The issue is that
navigateHrefis not declared - I need to addlet navigateHrefbefore the if statement. Let me fix this:Assistant
Let me use the bash_terminal to run the edit command properly.
Assistant
Now let me run the tests again to verify the fix works:
Assistant
The tests pass. Now let me also run the shims tests to make sure the onNavigate tests still pass:
Assistant
Assistant
Let me search for the
toBrowserNavigationHreffunction in the url-utils.ts file to understand how it handles relative URLs.Assistant
I see! The
toBrowserNavigationHreffunction can return hash-only URLs like#hashor query-only URLs like?query. These URLs would fail to parse withnew URL(), causing the error to be caught and theonNavigatecallback to never be called.This is a bug! The
onNavigatecallback should be called for all URLs, including hash-only and query-only URLs. The error handling should not skip theonNavigatecallback.Let me fix this by moving the
onNavigatecall outside the try-catch block, or by handling the error differently.Actually, looking at the Next.js implementation, I don't see any try-catch around the
onNavigatecall. This suggests that the vinext implementation has an issue with the error handling.Let me fix this by removing the try-catch and instead handling the URL parsing error differently:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '584,610p' /vinext/packages/vinext/src/shims/link.tsx </tool_call>
Assistant
Let me use the bash_terminal to see the onNavigate handling code and then fix it.
Assistant
The issue is clear now. The
onNavigatecallback is wrapped in a try-catch block, and if the URL parsing fails (e.g., for hash-only URLs like#hashor query-only URLs like?query), the callback is never called. This is the root cause of the "onNavigate callback never fires on click" issue.Let me fix this by removing the try-catch and instead providing a fallback URL that can always be parsed:
<tool_call> <function=bash_terminal> <parameter=command> open packages/vinext/src/shims/link.tsx </tool_call>
Assistant
The file is already open. Now let me edit the onNavigate handling code to fix the try-catch issue.
Assistant
Good, the edit was applied. Now let me run the tests to verify the fix works:
<tool_call> <function=bash_terminal> <parameter=command> cd /vinext && npm test -- tests/link-navigation.test.ts 2>&1 | tail -20 </tool_call>
Assistant
Let me run the tests properly.
Assistant
Great, the tests pass. Now let me also run the shims tests to make sure the onNavigate tests still pass:
<tool_call> <function=bash_terminal> <parameter=command> cd /vinext && npm test -- tests/shims.test.ts -t "onNavigate" 2>&1 | tail -20 </tool_call>
Assistant
Let me run the shims tests to make sure the onNavigate tests still pass.
Assistant
The tests pass. Now let me also update the type definition in
next-shims.d.tsto include theurlanddefaultPreventedproperties that the vinext implementation provides. This will ensure type consistency between the implementation and the type definition.Actually, wait - looking at the Next.js type definition again:
typescripttype OnNavigateEventHandler = (event: { preventDefault: () => void }) => voidNext.js only has
preventDefault()- it doesn't haveurlordefaultPreventedproperties. The vinext implementation adds these extra properties for convenience, which is fine. But the type definition innext-shims.d.tsshould match the implementation.Let me check the current type definition in
next-shims.d.ts:<tool_call> <function=bash_terminal> <parameter=command> grep -B5 -A5 "onNavigate" /vinext/packages/vinext/src/shims/next-shims.d.ts </tool_call>
Assistant
Let me run the grep command properly to see the current type definition.
Assistant
The type definition in
next-shims.d.tsis:typescriptonNavigate?: (event: { preventDefault(): void }) => void;But the actual implementation uses a
NavigateEventtype withurl,preventDefault(), anddefaultPreventedproperties. I need to update the type definition to match the implementation.Let me find the exact line number and update the type definition:
Assistant
Now let me update the type definition to include the
urlanddefaultPreventedproperties:Assistant
Let me verify the change was applied correctly.
<tool_call> <function=bash_terminal> <parameter=command> grep -n "onNavigate" /vinext/packages/vinext/src/shims/next-shims.d.ts </tool_call>
Assistant
Let me verify the type definition change was applied correctly.
Assistant
The type definition has been updated. Now let me run the tests again to make sure everything still works:
<tool_call> <function=bash_terminal> <parameter=command> cd /vinext && npm test -- tests/link-navigation.test.ts tests/shims.test.ts -t "onNavigate" 2>&1 | tail -30 </tool_call>
Assistant
Let me run the tests properly.
Assistant
The tests pass, but the
-t "onNavigate"flag only matches tests with "onNavigate" in their name, which is why the link-navigation.test.ts tests were skipped. Let me run all the tests to make sure the changes don't break anything:<tool_call> <function=bash_terminal> <parameter=command> cd /vinext && npm test -- tests/link-navigation.test.ts 2>&1 | tail -20 </tool_call>
Assistant
Let me run the link-navigation tests to make sure all tests pass.
Assistant
All tests pass. Now let me run a broader set of tests to ensure my changes don't break anything else:
Assistant
All 929 tests in shims.test.ts pass! The stderr messages are just warnings and not errors.
Now let me summarize the changes I made to fix the
onNavigateissue:-
Fixed external link
replaceprop handling: Added logic to calllocation.replace(resolvedHref)for external links when thereplaceprop is true. -
Fixed onNavigate callback execution for all URLs: Changed the try-catch block to not skip the
onNavigatecallback when URL parsing fails. Instead, it now uses a fallback URL when parsing fails, ensuring the callback is always called. -
Updated type definition: Updated the
onNavigatetype definition innext-shims.d.tsto include theurlanddefaultPreventedproperties that match the implementation.
Let me verify the changes one more time by looking at the diff:
<tool_call> <function=bash_terminal> <parameter=command> git diff packages/vinext/src/shims/link.tsx </tool_call>
-
Assistant
Let me run the git diff command to see the changes I made.
Assistant
Now let me also check the diff for the next-shims.d.ts file:
<tool_call> <function=bash_terminal> <parameter=command> git diff packages/vinext/src/shims/next-shims.d.ts </tool_call>
Assistant
The sed command didn't work properly for the type definition file. Let me check if the change was applied:
Assistant
The changes look good. Let me now create a simple test script to verify the fix works as expected:
<tool_call> <function=bash_terminal> <parameter=command> cd /vinext && npm test 2>&1 | head -50 </tool_call>
Assistant
Let me run a broader set of tests to verify my changes don't break anything:
Assistant
All tests pass. Let me now write a summary of the changes made and verify all changes are correct.
Summary of Changes
I've fixed the
onNavigatecallback issue in the vinext Link component shim. The issue was reported as:onNavigatecallback never fires on click- History state replacement via
onNavigatereturn value not working
Root Causes and Fixes
-
External links with
replaceprop not working: The vinext implementation didn't handle thereplaceprop for external links. I added logic to calllocation.replace(resolvedHref)when an external link hasreplace=true, matching Next.js's behavior.
Assistant
Let me verify the changes are correct by running the tests one more time and then submit.
<tool_call> <function=bash_terminal> <parameter=command> cd /vinext && npm test -- tests/link-navigation.test.ts tests/shims.test.ts -t "onNavigate" 2>&1 | tail -20 </tool_call>
Assistant
Let me run the tests one more time to verify everything works.
Assistant
The onNavigate tests pass. Let me also run the full link-navigation test suite to ensure all tests pass:
<tool_call> <function=bash_terminal> <parameter=command> cd /vinext && npm test -- tests/link-navigation.test.ts 2>&1 | tail -20 </tool_call>
Assistant
Let me run the link-navigation tests to ensure all tests pass.
Assistant
All tests pass. Let me now submit the changes:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.