cloudflare/vinext

Pages Router: `<Link>` `onClick` / `preventDefault()` semantics broken in new-link-behavior mode

已关闭

#1,470 创建于 2026年5月22日

 (0 条评论) (0 个反应) (0 位负责人)TypeScript (383 个派生)github user discovery
adapter-api-e2ehelp wanted

仓库指标

星标
 (8,624 个星标)
PR 合并指标
 (平均合并 1天 1小时) (30 天内合并 462 个 PR)

描述

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

Problem

The Pages Router <Link> shim does not correctly invoke onClick handlers and does not honor event.preventDefault() when running in new-link-behavior mode. Clicks on a Link with an onClick prop do not fire the user's handler, and preventDefault() inside it does not block the resulting navigation.

onClick prop not fired on Link click; preventDefault() does not block navigation

Estimated Impact

~2 test failures across the deploy suite.

Affected Test Suites

  • test/e2e/new-link-behavior/index.test.ts (2 failures)

Recommendation

  1. Reproduce first in vinext's own test suite. Add a <Link onClick={(e) => { e.preventDefault(); spy(); }} href="/x"> test and assert spy ran and the address bar did not change.

  2. Match Next.js click-handler semantics. Invoke onClick first, check event.defaultPrevented, and only call router.push() if the click is not prevented.

贡献者指南