Skip to content

fix: after selecting and dragging text, the table still scrolls even after releasing the mouse. #328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

QdabuliuQ
Copy link

@QdabuliuQ QdabuliuQ commented Jul 16, 2025

来源 ant-design issue:ant-design/ant-design#53924

bug复现:选择文本,鼠标按住文本拖拽到表格外边,松开鼠标,鼠标上下移动会触发表格滚动。demo 稳定复现
https://github.com/user-attachments/assets/9bec2f1c-866f-40d0-be9e-b6e19b6c0be8

查看源码后定位 rc-table / rc-virtual-list;在 rc-virtual-list 的 useScrollDrag hook 当中。

Summary by CodeRabbit

  • 优化
    • 改进滚动拖拽行为,提升在窗口失焦、页面隐藏、拖拽结束等多种场景下的稳定性和流畅度。

The package version was changed from 3.19.2 to 3.19.1, possibly to correct a versioning error or revert a previous update.
Copy link

vercel bot commented Jul 16, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
virtual-list ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 16, 2025 1:17pm

Copy link

coderabbitai bot commented Jul 16, 2025

Walkthrough

本次更改在 useScrollDrag 钩子中引入了 clearDragState 辅助函数,用于集中处理拖拽状态的重置。新增了多个事件监听器以在更多场景下清理拖拽状态,包括原生拖拽开始、窗口失焦和文档隐藏等,提升了滚动拖拽行为的健壮性。

Changes

文件/路径 变更摘要
src/hooks/useScrollDrag.ts 新增 clearDragState 函数,重构 onMouseUp,添加多种事件监听与清理逻辑,完善拖拽状态管理。

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Document
    participant useScrollDrag

    User->>Document: mousedown
    Document->>useScrollDrag: 开始拖拽
    User->>Document: mouseup/dragend/dragstart/blur/visibilitychange
    Document->>useScrollDrag: 触发 clearDragState
    useScrollDrag->>useScrollDrag: 重置拖拽状态
Loading

Possibly related PRs

Poem

小兔挥爪理拖拽,
状态清理不放开。
失焦隐藏皆照顾,
拖拽体验更畅快。
代码整洁又健壮,
滚动世界任我来!
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

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

src/hooks/useScrollDrag.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

Error: Cannot read config file: /.eslintrc.js
Error: Cannot find module '@umijs/fabric/dist/eslint'
Require stack:

  • /.eslintrc.js
  • /node_modules/.pnpm/@eslint[email protected]/node_modules/@eslint/eslintrc/dist/eslintrc.cjs
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/cli-engine/cli-engine.js
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/eslint/eslint.js
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/eslint/index.js
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/cli.js
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/bin/eslint.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1369:15)
    at defaultResolveImpl (node:internal/modules/cjs/loader:1025:19)
    at resolveForCJSWithHooks (node:internal/modules/cjs/loader:1030:22)
    at Module._load (node:internal/modules/cjs/loader:1179:37)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:235:24)
    at Module.require (node:internal/modules/cjs/loader:1449:12)
    at require (node:internal/modules/helpers:135:16)
    at Object. (/.eslintrc.js:1:14)
    at Module._compile (node:internal/modules/cjs/loader:1692:14)

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5769845 and 0ce568c.

📒 Files selected for processing (1)
  • src/hooks/useScrollDrag.ts (3 hunks)
🔇 Additional comments (7)
src/hooks/useScrollDrag.ts (7)

41-45: 很好的重构 - 集中管理拖拽状态清理逻辑

新增的 clearDragState 辅助函数有效地集中了状态重置逻辑,避免了代码重复。这样的重构提高了代码的可维护性和一致性。


63-63: 正确使用了新的辅助函数

将原来的内联逻辑替换为对 clearDragState() 的调用,保持了代码的简洁性和一致性。


67-69: 有效处理原生拖拽开始的边界情况

当用户开始原生拖拽操作时清理状态是一个很好的改进,这能防止在文本选择和拖拽场景下出现状态混乱。


72-74: 妥善处理窗口失焦场景

当窗口失去焦点时清理拖拽状态是必要的,因为在这种情况下后续的 mouseup 事件可能无法被正确捕获。


77-81: 正确处理页面可见性变化

检查 document.hidden 并在页面不可见时清理状态是一个周到的设计,能够处理用户切换标签页或最小化窗口等场景。


107-110: 全面的事件监听器覆盖

新增的事件监听器很好地覆盖了各种边界情况:

  • dragstartdragend 处理原生拖拽操作
  • blur 处理窗口失焦
  • visibilitychange 处理页面可见性变化

这些监听器的添加直接解决了 PR 目标中描述的问题。


116-119: 正确的事件监听器清理

所有新增的事件监听器都在 effect 清理函数中被正确移除,避免了内存泄漏和潜在的事件处理冲突。

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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.

1 participant