Skip to content

fix: only preventDefault on cancelable touchmove events - #539

Open
Pareder wants to merge 1 commit into
react-component:masterfrom
Pareder:fix/touchmove-prevent-default-cancelable
Open

Pareder wants to merge 1 commit into
react-component:masterfrom
Pareder:fix/touchmove-prevent-default-cancelable

Conversation

@Pareder

@Pareder Pareder commented Nov 20, 2026 •

Copy link
Copy Markdown

Closes #538

What

The window touchmove listener in useTouchEvent now calls preventDefault() only when e.cancelable is true.

Why

The preview opens while a touch-scroll gesture is sometimes still in progress. The remaining touchmove events in that gesture are not cancelable, so Chrome ignores preventDefault() and logs one intervention per event:

[Intervention] Ignored attempt to cancel a touchmove event with cancelable=false, for example because scrolling is in progress and cannot be interrupted.

Behaviour is unchanged: a non-cancelable event can't be prevented, and cancelable events are still blocked from scrolling the page.

Tests

  • New cases in tests/previewTouch.test.tsx
  • Manual check: Chrome DevTools device emulation and real Android device

Summary by CodeRabbit

  • Bug 修复
    • 预览打开且触摸移动事件可取消时,会阻止默认行为;事件不可取消、预览关闭或预览不可移动时,不会阻止默认行为。

@vercel

vercel Bot commented Nov 20, 2026

Copy link
Copy Markdown

@Pareder is attempting to deploy a commit to the React Component Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

全局 touchmove 处理器现在只在事件可取消时调用 preventDefault()。新增测试覆盖事件是否可取消、预览是否打开,以及 movable 配置。

Changes

touchmove 取消条件

Layer / File(s) Summary
事件取消检查与测试
src/hooks/useTouchEvent.ts, tests/previewTouch.test.tsx
处理器仅在事件可取消时调用 preventDefault()。新增测试覆盖可取消事件、不可取消事件、预览关闭及 movable: false。同时移除了 no-shadow 禁用注释。

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: aojunhao123

Merge Risk: Minimal · up to f057f

This change stops Chrome's "Ignored attempt to cancel a touchmove" warnings by calling preventDefault only on cancelable events. Scrolling is still blocked for cancelable events. No merge-blocking risk is evident.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 标题“fix: only preventDefault on cancelable touchmove events”准确描述了主要变更:全局 touchmove 监听器现在仅在 e.cancelable 为 true 时调用 preventDefault()。这与原始摘要和 PR 目标一致,目标是消除 Chrome 对不可取消事件的 “Ignored attempt to cancel a to…
Linked Issues check Passed 关联问题 [#538] 的核心要求是避免在不可取消的 touchmove 事件上调用 preventDefault(),从而消除 Chrome 的 "Ignored attempt to cancel a touchmove event" 警告。reviewed head 的 src/hooks/useTouchEvent.ts 中,window touchmove 监听函数 preventDef…
Out of Scope Changes check Passed 变更范围仅限于 src/hooks/useTouchEvent.ts 的 touchmove 监听守卫和 tests/previewTouch.test.tsx 中对应的测试。守卫修改直接实现 [#538] 的要求。摘要还提到在 onTouchEnd 中移除了 @typescript-eslint/no-shadow 禁用注释。该改动属于同一文件的小范围清理,与 touchmove 行为修改处于同…
Full details: Title check

Explanation

标题“fix: only preventDefault on cancelable touchmove events”准确描述了主要变更:全局 touchmove 监听器现在仅在 e.cancelable 为 true 时调用 preventDefault()。这与原始摘要和 PR 目标一致,目标是消除 Chrome 对不可取消事件的 “Ignored attempt to cancel a touchmove” 警告(关联 issue #538)。标题简短、具体,并包含 fix 类型前缀。

Full details: Linked Issues check

Explanation

关联问题 [#538] 的核心要求是避免在不可取消的 touchmove 事件上调用 preventDefault(),从而消除 Chrome 的 "Ignored attempt to cancel a touchmove event" 警告。reviewed head 的 src/hooks/useTouchEvent.ts 中,window touchmove 监听函数 preventDefault 现在先检查 e.cancelable,仅在为 true 时调用 e.preventDefault()。监听仍仅在 open && movable 时注册,且仍使用 passive: false。因此可取消事件仍被阻止滚动,不可取消事件不再触发 preventDefault()。该修改与 issue 的建议修复一致。PR 描述中的测试(tests/previewTouch.test.tsx 新增 61 行)覆盖可取消、不可取消、预览关闭和 movable: false 四种情形,摘要显示这些测试存在;本次未读取测试文件内容,故测试行为仅依据摘要判断。

Full details: Out of Scope Changes check

Explanation

变更范围仅限于 src/hooks/useTouchEvent.ts 的 touchmove 监听守卫和 tests/previewTouch.test.tsx 中对应的测试。守卫修改直接实现 [#538] 的要求。摘要还提到在 onTouchEnd 中移除了 @typescript-eslint/no-shadow 禁用注释。该改动属于同一文件的小范围清理,与 touchmove 行为修改处于同一 hook 内,未改变 onTouchEnd 的逻辑。未发现与 issue 无关的功能变更。本次未能读取 base 与 head 之间的文本 diff(changed blobs 缺失),因此上述判断基于 head 文件内容和摘要。

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
Fix failing CI checks

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

小兔看见触摸事件轻轻停下
可取消时才拦住默认动作
不可取消时,页面照常前行
预览开合都有测试看守
小兔蹦跳庆祝,耳朵摇呀摇

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 41f877f3-04d8-44b9-955f-5505c6179b6e
Commits

Reviewing files that changed from the base of the PR and between 4cbfa08 and f057f4d.

Files selected for processing: 2

  • src/hooks/useTouchEvent.ts
  • tests/previewTouch.test.tsx

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant