Skip to content
TheChatArchiveThe Chat Archive
composer-2.5· unknownHugging Face ibragim-bad/swe_rebench_07_2026_trajectories

<Link onNavigate> prop not implemented This issue was created by an agent analysing CI…

  1. User

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

  2. Assistant

    I'll implement the onNavigate prop on <Link> by studying Next.js's behavior and the current vinext shim, then adding tests and the fix.

  3. Assistant

    I'll add tests for the missing onNavigate cases and run them to see what's failing.

  4. Assistant

    Implementing remaining gaps: aligning external-link replace behavior with Next.js and hardening onNavigate so it isn't skipped by the try/catch.

  5. Assistant

    Implemented and hardened the <Link onNavigate> prop to match Next.js behavior.

    What changed

    onNavigate was already partially present in link.tsx, but the click handler had a few parity gaps:

    1. Silent skip risk — onNavigate was inside a try/catch around URL construction. If parsing failed, the callback was skipped while navigation still proceeded.
    2. External replace links — Next.js calls location.replace() for external URLs with replace; vinext returned early without doing that.
    3. Local vs external detection — Added isLocalURL() (mirroring Next.js) for consistent routing decisions.

    Implementation

    packages/vinext/src/shims/link.tsx

    • Uses isLocalURL() before intercepting clicks
    • Handles external replace via window.location.replace()
    • Calls onNavigate with a NavigateEvent (url, preventDefault(), defaultPrevented) before navigation
    • Respects preventDefault() on the navigate event to cancel navigation (for view transitions / locked navigation)

    packages/vinext/src/shims/url-utils.ts

    • Added isLocalURL() helper

    Tests added

    Ported cases from Next.js link-on-navigate-prop e2e into tests/link-navigation.test.ts:

    • onNavigate fires on internal navigation (App + Pages Router)
    • preventDefault() blocks navigation
    • Modifier keys, download, target="_blank", and external links do not call onNavigate
    • External replace links call location.replace() without calling onNavigate

    All 124 link-related unit tests pass.

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