Skip to content

fix: make touchmove cancelable so touch scrolling does not scroll the page - #394

Merged
yoyo837 merged 1 commit into
react-component:masterfrom
Pareder:fix/touch-scrolling
Nov 17, 2026
Merged

yoyo837 merged 1 commit into
react-component:masterfrom
Pareder:fix/touch-scrolling

Conversation

@Pareder

@Pareder Pareder commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Touch scrolling a virtual list logs this warning on every touchmove, and the page scrolls together with the list:

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

Cause

Browsers decide whether a touch sequence can be cancelled by checking for non-passive touch listeners when the touch begins. In useMobileTouchMove, the list only has a passive touchstart listener at that point. The non-passive touchmove listener is added to e.target inside onTouchStart, after the check has already run. Every touchmove then arrives with cancelable: false, so preventDefault() is ignored and the page's native scroll goes ahead.

Fix

  • When the hook mounts, register a no-op touchmove listener with { passive: false } on the list element, so the list area already counts as blocking when a touch begins. The real handler stays on e.target: virtualized items can be unmounted mid-swipe, and events on a detached target never bubble up to the list. Nested lists still go through the existing _virtualHandled check.
  • Only call e.preventDefault() when e.cancelable is true. Moves can still be non-cancelable after a swipe passes the list's top or bottom edge and the page takes over the scroll (originScroll). Calling it there only logged the warning.

CSS touch-action: none on the holder would also block native scrolling, but it can't be switched per move. It would stop the page from taking over at the list edges, which originScroll relies on.

Tests

  • Added a test that the list registers a non-passive touchmove listener before any touch starts.
  • Added a test that preventDefault is not called on a non-cancelable touchmove.
  • In "not call when not scroll-able", the synthetic touchmove events are now created with cancelable: true, like real ones.
  • Both new tests fail without the fix. The full suite passes (305 tests), and tsc is clean.
  • Manual check: Chrome DevTools device emulation

Closes #393

Summary by CodeRabbit

  • 修复
    • 改进虚拟列表的触摸滚动处理:仅在事件可取消且已被处理时阻止默认滚动行为。
    • 修复触摸开始前列表区域的滚动拦截设置,并确保清理时移除相关监听器。

@vercel

vercel Bot commented Nov 16, 2026

Copy link
Copy Markdown

@Pareder is attempting to deploy a commit to the afc163's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

虚拟列表现在会在列表元素上注册非被动的 touchmove 监听器,并在清理时移除。触摸处理仅在事件可取消时调用 preventDefault。测试覆盖监听器注册和不可取消事件。

Changes

触摸滚动处理

Layer / File(s) Summary
监听器注册与默认行为处理
src/hooks/useMobileTouchMove.ts, tests/touch.test.js
虚拟列表在列表元素上注册并清理非被动的 touchmove 监听器。触摸目标上的处理逻辑仅在事件可取消时调用 preventDefault。测试覆盖监听器选项、可取消事件及不可取消事件。

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

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: zombiej, linxianxi

Merge Risk: Minimal · up to 52186

This change lets swiping inside a virtual list scroll the list without also scrolling the page, and it avoids browser warnings about non-cancelable events. No merge-blocking risk was found.

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: make touchmove cancelable so touch scrolling does not scroll the page”准确描述了主要变更。变更内容包括:为列表注册非被动的 touchmove 监听器,并且仅在事件可取消时调用 preventDefault,从而阻止触摸滚动带动页面滚动。标题与 PR 目标(修复 issue #393)一致,且未包含无关内容。
Linked Issues check Passed 针对 Issue [#393] 的编码要求已在 src/hooks/useMobileTouchMove.ts 中实现,且与 Issue 的修复方案一致:
1. 在 useLayoutEffect 中,当 inVirtual 为 true 时,为列表元素 listEle 注册 touchmove 空监听器 onListTouchMove,选项为 { passive: false }。该监听器在 t…
Out of Scope Changes check Passed 变更仅涉及 src/hooks/useMobileTouchMove.ts 与 tests/touch.test.js。所有改动都直接对应 Issue [#393] 的两项修复方案:空的非被动 touchmove 监听器、保留 e.target 上的真实处理、以及仅在 e.cancelable 为真时调用 preventDefault。测试改动用于验证这些行为。未发现与 Issue 无关的改动。注…
Full details: Linked Issues check

Explanation

针对 Issue [#393] 的编码要求已在 src/hooks/useMobileTouchMove.ts 中实现,且与 Issue 的修复方案一致:

  1. 在 useLayoutEffect 中,当 inVirtual 为 true 时,为列表元素 listEle 注册 touchmove 空监听器 onListTouchMove,选项为 { passive: false }。该监听器在 touchstart 之前即存在,使列表区域在触摸开始时被浏览器判定为阻塞。清理函数会移除该监听器。
  2. 真实的 onTouchMove 处理仍绑定在 e.target 上(onTouchStart 中),避免虚拟列表项在滑动中卸载后事件无法冒泡到列表的问题。
  3. onTouchMove 中仅当 scrollHandled 为真且 e.cancelable 为真时才调用 e.preventDefault(),消除了 originScroll 之后不可取消事件产生的警告。

未检查测试文件的 diff 内容。PR 描述与原始摘要称新增了两项测试,并修改了 "not call when not scroll-able" 中的合成事件。这些测试不属于 Issue 的明确要求,因此不影响本项结论。

Full details: Out of Scope Changes check

Explanation

变更仅涉及 src/hooks/useMobileTouchMove.ts 与 tests/touch.test.js。所有改动都直接对应 Issue [#393] 的两项修复方案:空的非被动 touchmove 监听器、保留 e.target 上的真实处理、以及仅在 e.cancelable 为真时调用 preventDefault。测试改动用于验证这些行为。未发现与 Issue 无关的改动。注意:未读取 tests/touch.test.js 的 diff 内容,测试部分的结论基于 PR 描述与摘要。

Finishing Touches

Generate unit tests (beta)

  • 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: c2927a04-380e-42ee-ac81-b70f2f5d5508
Commits

Reviewing files that changed from the base of the PR and between 17ca15a and 52186f0.

Files selected for processing: 2

  • src/hooks/useMobileTouchMove.ts
  • tests/touch.test.js

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

@codecov

codecov Bot commented Nov 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.90%. Comparing base (17ca15a) to head (52186f0).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #394   +/-   ##
=======================================
  Coverage   97.89%   97.90%           
=======================================
  Files          20       20           
  Lines         902      906    +4     
  Branches      219      215    -4     
=======================================
+ Hits          883      887    +4     
  Misses         19       19           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yoyo837
yoyo837 merged commit 47882c1 into react-component:master Nov 17, 2026
11 of 12 checks passed
yanyubot added a commit to antdv-next/vue-components that referenced this pull request Nov 18, 2026
…omponent (#129)

* fix(drawer): do not coerce empty string width or height to zero (react-component/drawer#631)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(pagination): add uz_Cyrl_UZ locale (react-component/pagination#730)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(picker): add Uzbek Cyrillic (uz_Cyrl_UZ) locale (react-component/picker#1027)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(virtual-list): make touchmove cancelable so touch scrolling does not scroll the page (react-component/virtual-list#394)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore(sync): advance color-picker, drawer, pagination, picker, virtual-list cursor to b8cf756a89, c5220e7155, 2728b339b2, 354232c516, 47882c1cf2

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: yanyubot <356405855+yanyubot@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Touch scrolling a virtual list logs "Ignored attempt to cancel a touchmove event" and scrolls the page

2 participants