Skip to content
TheChatArchiveThe Chat Archive
xiaomi/mimo-v2.5-pro· unknownHugging Face ibragim-bad/swe_rebench_07_2026_trajectories

ISSUE DESCRIPTION <Link onNavigate> prop not implemented This issue was created by an…

  1. User

    ISSUE DESCRIPTION

    <Link onNavigate> prop not implemented

    This issue was created by an agent analysing CI failures from the Next.js Deploy Suite (vinext main vs Next.js v16.2.6, 2026-05-20).

    Problem

    The onNavigate callback prop on <Link> (added in Next.js 15) does not fire. Tests that rely on onNavigate to detect navigations, intercept them, or track click state all fail.

    Specific failures include:

    • onNavigate callback never fires on click
    • Click state tracking broken (link thinks it was never clicked)
    • History state replacement via onNavigate return value not working

    Estimated Impact

    ~8 test failures.

    Affected Test Suites

    • test/e2e/link-on-navigate-prop/index.test.ts (8 failures)

    Recommendation

    1. 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.

    2. Study the Next.js implementation. Search .nextjs-ref/packages/next/src/client/link.tsx for onNavigate to 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).

    3. Implement onNavigate in the next/link shim. The Link component needs to call onNavigate before 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 using git reset --hard command. Additionally, you can use git stash and git stash pop to 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 submit) using git status or git diff commands. However you don't need to use git add or git commit before submitting your changes. In fact, submit only submits currently unstaged changes because it uses git diff to get the changes that need to be submitted.

    CHECKLIST

    Before submitting your solution, please go over the following checklist and make sure you've done everything:

    • If an error was reported in the issue description, I have successfully reproduced it.
    • If an error was reported in the issue description, I have confirmed that my fix resolves the error.
    • I have thought about edge cases and made sure my fix handles them as well.
    • I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.

    Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!

    (Current directory: /vinext, current file: none) bash-$

  2. Assistant

    I'll start by exploring the repository structure to understand the codebase. Let's first see what's in the root directory.

  3. Assistant

    Let me explore the repository structure more thoroughly.

  4. Assistant

    Let me understand the project structure better. It seems to be a monorepo with packages, apps, tests, etc. I need to find the next/link shim implementation.

  5. Assistant

    Let me examine the existing Link implementation and also look at the test that's failing.

  6. Assistant

    Let me look at the test file that's failing:

  7. Assistant

    Let me search for the test file mentioned in the issue.

  8. Assistant

    Let me search more broadly for test files related to link on navigate.

  9. Assistant

    Let me look at the test directory structure.

  10. Assistant

    Let me look at the existing tests for link to understand the pattern, and also look for the specific test mentioned in the issue.

  11. Assistant

    Let me look at the relevant test files and the existing link implementation more carefully.

  12. Assistant

    Now let me look at the test mentioned in the issue - the e2e test:

  13. Assistant

    Let me search for the e2e test directory structure:

  14. Assistant

    Let me search for the specific test file mentioned in the issue. mentioned in the issue.

  15. Assistant

    Let me search for the specific test file mentioned in the issue.

  16. Assistant

    Let me look at the existing e2e navigation test and the link test:

  17. Assistant

    Let me look at the tests/e2e/pages-router/link-advanced.spec.ts and also the relative-query-link.tsx fixture to understand how onNavigate is being used:

  18. Assistant

    Now let me look at the Next.js reference implementation to understand the expected API contract:

  19. Assistant

    Let me look at how onNavigate is currently handled in the link.tsx:

  20. Assistant

    Let me look at the relevant section of the link.tsx file where onNavigate is used:

  21. Assistant

    Let me look at the full function signature and how props are destructured:

  22. Assistant

    Let me look at the full Link component function to see how the props are destructured and how onNavigate is used.

  23. Assistant

    Let me look at the link test file and the Next.js reference if available:

  24. Assistant

    Let me look at the tests/link-navigation.test.ts more closely for onNavigate tests:

  25. Assistant

    Let me look at the Next.js implementation of onNavigate:

  26. Assistant

    Let me look at the existing shims.test.ts file:

  27. Assistant

    Let me look at the relevant part of shims.test.ts around line 14701.

  28. Assistant

    Let me look at the test fixtures and understand the existing onNavigate behavior:

  29. Assistant

    Let me check the pages-basic fixture too:

  30. Assistant

    Let me look at the pages-basic link-test.tsx file:

  31. Assistant

    Now let me look at the e2e tests directory more carefully:

  32. Assistant

    The test file mentioned in the issue description (test/e2e/link-on-navigate-prop/index.test.ts) doesn't exist in the repository. The issue says there are approximately 8 test failures in that test suite. Let me check what Next.js actually expects from the onNavigate prop:

  33. Assistant

    Let me check if there are any Next.js source references:

  34. Assistant

    Let me look at the AGENTS.md for more guidance:

  35. Assistant

    Let me look at the Next.js link.tsx reference implementation for onNavigate:

  36. Assistant

    Let me run the existing tests first to understand what's happening:

  37. Assistant

    Let me try running tests differently:

  38. Assistant

    Let me understand the issue better. Let me look at how the e2e tests reference onNavigate behavior, and check the Next.js implementation:

  39. Assistant

    Now I can see the key reference - tests/link-navigation.test.ts references Next.js test/e2e/link-on-navigate-prop/index.test.ts. Let me look at the full download test that uses onNavigate:

  40. Assistant

    Let me check if there's a .nextjs-ref directory or if the Next.js source code is available anywhere:

  41. Assistant

    Let me check if Next.js is installed in node_modules:

  42. Assistant

    Let me look at the Next.js reference implementation of Link:

  43. Assistant

    Let me look at the actual implementation of linkClicked function in Next.js:

  44. Assistant

    Interesting! Let me see more of the Next.js implementation:

  45. Assistant

    Let me look at the Next.js link.d.ts type definitions:

  46. Assistant

    Now let me look at the App Router Link implementation in Next.js (the one we looked at is for Pages Router):

  47. Assistant

    Let me look at the app-dir/link.js file since vinext is primarily an App Router tool:

  48. Assistant

    Let me look at the app-dir linkClicked function:

  49. Assistant

    Now I understand the Next.js implementation. Let me check the Next.js test for onNavigate:

  50. Assistant

    Now I have a clear picture of the Next.js implementation. Let me look at the Next.js test expectations. First, let me find the Next.js test file:

  51. Assistant

    Let me try to run the existing unit tests to see what happens:

  52. Assistant

    Let me try running just the link-navigation test:

  53. Assistant

    Let me look at the vite config to understand how to run tests:

  54. Assistant

    Let me try running tests more directly with the vite-plus test runner:

  55. Assistant

    Let me try a different approach. Let me run the tests using vp test:

  56. Assistant

    Good, the existing link-navigation tests pass. Now let me look more carefully at the full link-navigation test to understand the onNavigate tests:

  57. Assistant

    Let me look at the full test file to understand the renderIsolatedLink helper:

  58. Assistant

    Now I understand the situation clearly. Let me look at the full test file structure to understand where to add an onNavigate test:

  59. Assistant

    Let me look at the full "Link App Router navigation scheduling" section that includes the onNavigate test:

  60. Assistant

    Now I have a good understanding of the current implementation and what Next.js 16.2.6 does. Let me check the dist version to make sure onNavigate is in the built output:

  61. Assistant

    Let me look at the full built onNavigate section:

  62. Assistant

    Let me look at the full Link component to understand what tests might be failing. Let me also check the next-shims.d.ts file:

  63. Assistant

    Now I have a clear picture. Let me understand the key differences between Next.js's onNavigate implementation and vinext's:

    1. Next.js 16.2.6: onNavigate receives { preventDefault } (just the function, no URL or defaultPrevented)
    2. Vinext: onNavigate receives { url, preventDefault, defaultPrevented } (superset)

    The issue says ~8 test failures from test/e2e/link-on-navigate-prop/index.test.ts. Let me first try to reproduce by adding tests. Let me look at what tests the Next.js reference test might include:

  64. Assistant

    Let me take a practical approach - create a simple reproduce test to check if onNavigate actually fires:

  65. Assistant

    I need to put the test file in the tests directory. Let me create it there:

  66. Assistant

    The basic tests pass! The onNavigate callback fires correctly. Let me now think about what might be failing in the E2E tests. Let me look at the Next.js source code for test/e2e/link-on-navigate-prop/index.test.ts:

  67. Assistant

    Let me check if the Next.js source or test reference is available somewhere:

  68. Assistant

    Let me look at the Next.js links.js to understand the LinkStatus/pending state:

  69. Assistant

    Now let me look at the full Next.js app-dir Link component more carefully to understand the useLinkStatus implementation:

  70. Assistant

    Let me carefully understand the full picture. I need to check what the Next.js 16.2.6 test suite expects. Let me look at what files exist in the Next.js package:

  71. Assistant

    Let me check more carefully what the issue is about. Let me look at the Next.js link implementation's onNavigate more carefully and compare with vinext:

  72. Assistant

    Let me take a step back and look at the broader picture. I notice the issue mentions test/e2e/link-on-navigate-prop/index.test.ts - this is a Next.js test file that is run against vinext. Let me check if there's a reference to this test anywhere:

  73. Assistant

    Let me check the exact Next.js version installed and look at its type definitions more carefully:

  74. Assistant

    OK, so we're working with Next.js 16.2.6. Let me now look at the next/link.d.ts more carefully to see if there's something I'm missing:

  75. Assistant

    Let me look at the dist/client/link.d.ts:

  76. Assistant

    Let me look at the view-transitions example to understand how onNavigate is used:

  77. Assistant

    Now I have a thorough understanding of the situation. Let me clean up the temporary test file and think about what changes might actually be needed:

  78. Assistant

    Let me take a deeper look at the actual issue. Let me run the full unit test suite and see what's failing:

  79. Assistant

    All 1042 tests pass. Now let me understand what the issue really is about. Let me look at the Next.js link-on-navigate-prop test more carefully. The issue says "History state replacement via onNavigate return value not working". Let me check if the Next.js canary branch has a different onNavigate API:

  80. Assistant

    Let me look at the full Pages Router link.js for onNavigate:

  81. Assistant

    Let me look at the toBrowserNavigationHref function to understand potential edge cases:

  82. Assistant

    OK, I think I've been overthinking this. Let me take a completely different approach.The issue says:

    1. "<Link onNavigate> prop not implemented"

    2. ~8 test failures from test/e2e/link-on-navigate-prop/index.test.ts

    3. Specific failures: callback never fires, click state tracking broken, history state replacement via return valueLooking at the code, onNavigate IS implemented. But there are some issues I can identify:

    4. The onNavigate event in vinext includes url and defaultPrevented which Next.js doesn't provide. This is a superset and shouldn't break tests.

    5. The onNavigate is called AFTER e.preventDefault() which matches Next.js behavior.

    6. The navigation via startTransition + navigateClientSide should work.

    Wait, but the issue says "History state replacement via onNavigate return value not working". Let me look at the Next.js implementation again more carefully.

    In the Next.js app-dir link.js:

    if (onNavigate) {
        let isDefaultPrevented = false;
        onNavigate({
            preventDefault: ()=>{
                isDefaultPrevented = true;
            }
        });
        if (isDefaultPrevented) {
            return;
        }
    }
    

    In the Next.js pages-dir link.js, it's the same pattern. The onNavigate callback receives { preventDefault } only. The return value is NOT used.

    But the issue says "History state replacement via onNavigate return value". This doesn't match the Next.js 16.2.6 API at all.

    Hmm wait, let me look at the next-shims.d.ts again more carefully:

  83. Assistant

    Let me look for any fixture pages that might be related to the onNavigate test:

  84. Assistant

    Let me look at the next-shims.d.ts to understand the type definitions:

  85. Assistant

    Let me look at the CI configuration to understand the Next.js Deploy Suite:

  86. Assistant

    Let me look at the nextjs-deploy-suite workflow:

  87. Assistant

    Now I understand! The Next.js Deploy Suite runs Next.js's e2e tests against vinext. The test file test/e2e/link-on-navigate-prop/index.test.ts is from the Next.js repository itself. Let me look at the deploy script to understand the setup:

  88. Assistant

    Let me check the deploy manifest to see if the link-on-navigate-prop test is included:

  89. Assistant

    Let me check if there's a Next.js checkout in the workspace:

  90. Assistant

    Let me look at this from a completely different angle. Since I know the existing code works for unit tests, let me understand the exact Next.js test expectations. Let me check what happens when a test from the Next.js Deploy Suite runs against vinext. Let me look at the deploy script's e2e-deploy.sh:

  91. Assistant

    Let me approach this differently. I've verified the basic onNavigate works. The issue is about ~8 test failures from the Next.js Deploy Suite. Let me look more carefully at the specific differences between vinext and Next.js:

  92. Assistant

    Now I have a thorough understanding. Let me think about what the actual problem might be.

    Looking at the Next.js 16.2.6 implementation vs vinext:

    Key observation: In Next.js's linkClicked, onNavigate receives only { preventDefault }. In vinext's handleClick, onNavigate receives { url, preventDefault, defaultPrevented }. This is a superset.

    However, looking more carefully at the issue:

    • "History state replacement via onNavigate return value not working"

    Looking at the Next.js types: onNavigate?: (event: { preventDefault: () => void }) => void; — the return type is void.

    Wait, but in vinext's NavigateEvent type, there's defaultPrevented getter. What if some test code checks event.defaultPrevented BEFORE calling preventDefault() and expects false?

    Actually, looking at the existing vinext tests and code, the implementation appears to work correctly. Let me focus on what might actually be the 8 failing tests. The issue references the Next.js test/e2e/link-on-navigate-prop/index.test.ts test. This is an E2E test from the Next.js test suite, run via the deploy suite.

    Given the issue says the onNavigate callback "never fires on click", and my unit tests show it DOES fire, there might be a difference in the E2E environment. Let me check if there's something about the click handler that could fail in a real browser:

    Looking at the click handler:

    const handleClick = async (e: MouseEvent<HTMLAnchorElement>) => {
        if (onClick) onClick(e);
        if (e.defaultPrevented) return;
        // ...
        e.preventDefault();
        // ...
        if (onNavigate) {
          try {
            const navUrl = new URL(absoluteFullHref, window.location.origin);
            // ...
            onNavigate(navEvent);
            // ...
          } catch {
            // Ignore URL parsing errors for relative/hash hrefs
          }
        }
    

    Wait, there's a potential issue! e.preventDefault() is called BEFORE onNavigate. This means e.defaultPrevented would be true when onNavigate runs. But in the Next.js implementation, e.preventDefault() is also called before onNavigate, so this should be the same.

    Actually, the issue says "onNavigate callback never fires on click". But it IS in the code. Let me verify the dist file matches:

  93. Assistant

    Let me take a practical approach. Looking at the code carefully, the implementation exists but I notice the comment says "Return value is ignored" for the onNavigate callback. Let me now compare what the Next.js test expects vs what vinext provides, by looking at the type definitions more carefully:

  94. Assistant

    OK, I've spent a lot of time analyzing. Let me now focus on actually making improvements. Let me look at what specific improvements are needed based on the issue and the Next.js implementation:

  95. Assistant

    OK, I've spent a lot of time analyzing. Let me now focus on concrete changes. Based on my thorough analysis:

    1. The onNavigate IS implemented and works correctly in unit tests
    2. The Next.js 16.2.6 onNavigate API passes { preventDefault } only
    3. The Next.js test suite test/e2e/link-on-navigate-prop/index.test.ts runs against vinext

    Looking at the code, I can see that the implementation works, but there are some potential issues with the try/catch wrapping the onNavigate call. If new URL() throws, onNavigate never fires. Let me fix this and add comprehensive tests.

  96. Assistant

    Now let me fix the code. The key issue is that the try/catch wraps the entire onNavigate call, which means if new URL() throws, onNavigate never fires. Let me fix this:

  97. Assistant

    Now let me make the fix. The try/catch wrapping the entire block means if new URL() throws, onNavigate never fires. I need to restructure so onNavigate always fires:

  98. Assistant

    Let me use the terminal to make the edit:

  99. Assistant

    Let me use the open and edit commands to make the change.

  100. Assistant

    Now I can see the exact code to replace. Let me use the edit command.

  101. Assistant

    Good, the edit was applied. Now let me also update the NavigateEvent type comment to clarify that url is a vinext extension, and update the onNavigate prop documentation. Let me also look at the dist file to update it:

  102. Assistant

    Good. Now let me run the tests to make sure everything still passes:

  103. Assistant

    Good, all tests pass. Now let me also rebuild the dist to reflect the change:

  104. Assistant

    Let me check how vinext is built:

  105. Assistant

    Let me find the package.json for vinext:

  106. Assistant

    The current directory has changed to the file path. Let me go back to the root.

  107. Assistant

    Let me build vinext properly:

  108. Assistant

    The build is timing out. Let me just update the dist file manually to match the source change:

  109. Assistant

    Now let me update the dist file to match the source change:

  110. Assistant

    I notice the indentation is wrong in the dist file. Let me fix it:

  111. Assistant

    Good, the indentation is now correct. Let me run the tests again to make sure everything still passes:

  112. Assistant

    All 1042 tests pass. Now let me also fix the click state tracking for Pages Router by adding setPending(true/false):

  113. Assistant

    Now let me add setPending to the Pages Router path:

  114. Assistant

    Good, the edit was applied. Now let me update the dist file as well:

  115. Assistant

    I see the indentation is wrong. Let me fix it:

  116. Assistant

    Good, the dist file looks correct now. Let me run the tests again to make sure everything still passes:

  117. Assistant

    All 1042 tests still pass. Let me now review the full diff to make sure the changes are correct:

  118. Assistant

    Let me also check the dist diff:

  119. Assistant

    The dist file diff is empty? Let me check if the dist file is tracked by git.

  120. Assistant

    Hmm, the dist file diff is empty. This suggests the dist file is not tracked by git. Let me check if it's in .gitignore.

  121. Assistant

    Let me check if the dist file is tracked by git:

  122. Assistant

    The dist file is not tracked by git. That's fine - the dist file is built from the source. The important thing is that the source file changes are correct.

    Let me check git status more carefully.

  123. Assistant

    Good, only the source file is changed. The dist file is not tracked by git (it's likely in .gitignore). Let me verify the changes look correct by reviewing the full diff one more time:

  124. Assistant

    The changes look correct. Let me now run the lint check to make sure the code follows the project's style:

  125. Assistant

    All checks pass. Let me now verify the dist file one more time to make sure it's correct:

  126. Assistant

    Good, the dist file has the correct changes. Let me now do a final review of the complete changes:

  127. Assistant

    Good, the dist file looks correct. Let me now run the full test suite one final time to make sure everything passes:

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.