Skip to content

fix: stop scrollbar touchstart warnings during momentum scroll - #396

Open
Pareder wants to merge 1 commit into
react-component:masterfrom
Pareder:fix/scrollbar-touchstart-cancelable
Open

Pareder wants to merge 1 commit into
react-component:masterfrom
Pareder:fix/scrollbar-touchstart-cancelable

Conversation

@Pareder

@Pareder Pareder commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Closes #395

While a momentum scroll is running, the browser dispatches touchstart with cancelable: false. The scrollbar's track and thumb touchstart handlers called preventDefault() unconditionally, which logged an [Intervention] warning. Since that call was ignored, the page could also scroll during a thumb drag.

  • Set touch-action: none on the scrollbar container. It keeps the page from panning whether or not the touchstart is cancelable.
  • Only call preventDefault() when e.cancelable is true.

Tests: added cases for a non-cancelable touchstart on the track and on the thumb (no preventDefault, and the thumb drag still starts), plus a check for the touch-action style. They fail without the fix; the full suite passes.

Follow-up to #394.

Summary by CodeRabbit

  • Bug Fixes
    • 修复滚动条触摸操作可能带动页面平移的问题。
    • 不可取消的触摸事件不会调用阻止默认行为的方法,滑块仍可进入拖动状态。
  • Tests
    • 补充对不可取消触摸事件及滚动条触摸行为的验证。

@vercel

vercel Bot commented Nov 20, 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 20, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

滚动条的触摸开始处理现在会检查事件是否可取消。滚动条容器设置 touch-action: none。新增测试覆盖动量滚动期间,轨道和滑块收到不可取消的触摸事件时的行为。

Changes

滚动条触摸处理

层 / 文件 摘要
触摸处理与验证
src/ScrollBar.tsx, tests/touch.test.js
轨道和滑块仅在触摸事件可取消时调用 preventDefault()。滚动条容器设置 touch-action: none。测试验证不可取消事件不会调用 preventDefault()、滑块仍进入拖动状态,并检查容器的 touchAction。

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

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: zombiej, yoyo837

Merge Risk: Minimal · up to 394a4

This change stops the console warning when the scrollbar is touched during momentum scrolling and keeps thumb dragging working. The change is small and tested, and 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: stop scrollbar touchstart warnings during momentum scroll”与变更内容一致。变更让滚动条在不可取消的 touchstart 事件中不调用 preventDefault,并为滚动条容器设置 touch-action: none,从而避免惯性滚动期间的警告和页面平移。标题简洁,并指出了主要修复点和触发场景。
Linked Issues check Passed [#395] 要求三项行为:(1) 滚动条触摸不阻止惯性滚动之外的页面平移;(2) 拖动滑块时页面不滚动;(3) 控制台无 Intervention 警告。

已在 src/ScrollBar.tsx 的 diff 中确认以下变更:
- 轨道 touchstart 处理函数 onScrollbarTouchStart 仅在 e.cancelable 为 true 时调用 e.preventDefa…
Out of Scope Changes check Passed 全部变更均限于 src/ScrollBar.tsx 与 tests/touch.test.js。源码变更仅涉及滚动条触摸开始处理与容器样式,直接对应 #395 的根因与建议修复。tests/touch.test.js 的变更(不可取消 touchstart 的测试、touch-action 样式检查)用于验证同一目标行为,属于支持性测试,不属于范围外变更。未发现与 #395 无关的重构或功能变更。
Full details: Linked Issues check

Explanation

[#395] 要求三项行为:(1) 滚动条触摸不阻止惯性滚动之外的页面平移;(2) 拖动滑块时页面不滚动;(3) 控制台无 Intervention 警告。

已在 src/ScrollBar.tsx 的 diff 中确认以下变更:

  • 轨道 touchstart 处理函数 onScrollbarTouchStart 仅在 e.cancelable 为 true 时调用 e.preventDefault()。这满足 #395 的第二项建议修复,也避免不可取消事件触发警告。
  • 滑块按下处理函数(thumb 的 touchstart/mousedown 路径)仅在 e.cancelable 为 true 时调用 e.preventDefault()。stopPropagation 与 onStartMove 保留不变,滑块拖动仍会启动。
  • 滚动条容器 containerStyle 新增 touchAction: 'none'。该样式在触摸开始时生效,不依赖事件是否可取消,满足 #395 的第一项建议修复,并覆盖页面平移问题。

未发现 #395 中与编码相关的未满足要求。tests/touch.test.js 的新增测试未在本次检查中直接读取,结论基于源码 diff 及 PR 摘要中对测试的描述。

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: 7f15051d-a2a1-41dd-85f0-fec01fcca4a2
Commits

Reviewing files that changed from the base of the PR and between 47882c1 and 394a42f.

Files selected for processing: 2

  • src/ScrollBar.tsx
  • 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 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.90%. Comparing base (47882c1) to head (394a42f).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #396   +/-   ##
=======================================
  Coverage   97.90%   97.90%           
=======================================
  Files          20       20           
  Lines         906      908    +2     
  Branches      215      217    +2     
=======================================
+ Hits          887      889    +2     
  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.

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

Development

Successfully merging this pull request may close these issues.

Touching the scrollbar during a momentum scroll logs "Ignored attempt to cancel a touchstart event" and lets the page scroll during thumb drag

1 participant