Skip to content
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

fix: fix tabs scroll slowly in some version #658

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

Conversation

xiefenga
Copy link

@xiefenga xiefenga commented Mar 10, 2023

add the conversion of line number to pixel value when the scroll value is line number in the wheel event
related issue: Tabs scroll slowly in firefox some version such as 72.0 #657

Summary by CodeRabbit

  • 新功能

    • 引入了 isLineModegetWheelDeltaOfPx 函数,以改进对滚轮事件的处理。
  • 改进

    • 更新了 onWheel 函数,使用新的工具函数获取滚轮事件的增量值。

@vercel
Copy link

vercel bot commented Mar 10, 2023

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

Name Status Preview Comments Updated (UTC)
tabs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 29, 2024 8:36am

@afc163
Copy link
Member

afc163 commented Sep 29, 2024

Conflicting

Copy link

coderabbitai bot commented Sep 29, 2024

Walkthrough

此次更改涉及 src/hooks/useTouchMove.tssrc/util.ts 文件。useTouchMove.ts 文件中重新排列了导入语句,并修改了 onWheel 函数的实现方式,使用 getWheelDeltaOfPx 函数来获取 deltaXdeltaY 的值。util.ts 文件中新增了两个函数:isLineModegetWheelDeltaOfPx,用于处理 WheelEvent 的像素值计算和模式检查。

Changes

文件 更改摘要
src/hooks/useTouchMove.ts 导入语句重新排序,onWheel 函数实现修改,使用 getWheelDeltaOfPx 获取 deltaXdeltaY
src/util.ts 新增 isLineModegetWheelDeltaOfPx 函数,修改 React 导入语句。

Poem

🐇 在代码的世界里欢跃,
变更如春风轻拂面颊。
新函数如花绽放,
轮滚动,像舞蹈,
让我们一起欢庆这变化,
编程的乐趣无穷无尽,
兔子在此祝贺,快乐无边! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (3)
src/util.ts (2)

29-31: isLineMode 函数实现正确。

这个函数很好地实现了检查滚轮事件是否处于行模式的功能。为了提高可读性,您可以考虑使用常量来表示 WheelEvent.DOM_DELTA_LINE

建议的改进:

+ const DOM_DELTA_LINE = WheelEvent.DOM_DELTA_LINE;
export function isLineMode(event: WheelEvent) {
-  return event.deltaMode === WheelEvent.DOM_DELTA_LINE
+  return event.deltaMode === DOM_DELTA_LINE;
}

这样可以提高代码的可读性和可维护性。


33-42: getWheelDeltaOfPx 函数实现正确,但有改进空间。

这个函数很好地实现了将滚轮事件的 delta 值转换为像素值的功能。然而,有几点可以改进:

  1. 使用对象返回值而不是数组可能会更清晰。
  2. 将缩放因子 (100/3) 提取为一个命名常量可以提高可读性和可维护性。
  3. 可以使用对象解构来简化代码。

建议的改进:

+ const LINE_HEIGHT_PX = 100 / 3;

- export function getWheelDeltaOfPx(event: WheelEvent) {
-   const { deltaX, deltaY } = event
-   const deltaXOfPx = isLineMode(event)
-     ? deltaX * 100 / 3
-     : deltaX;
-   const deltaYOfPx = isLineMode(event)
-     ? deltaY * 100 / 3
-     : deltaY;
-   return [deltaXOfPx, deltaYOfPx]
- }
+ export function getWheelDeltaOfPx(event: WheelEvent): { deltaXOfPx: number; deltaYOfPx: number } {
+   const { deltaX, deltaY } = event;
+   const scale = isLineMode(event) ? LINE_HEIGHT_PX : 1;
+   return {
+     deltaXOfPx: deltaX * scale,
+     deltaYOfPx: deltaY * scale
+   };
+ }

这些改变将使函数更易于理解和维护,同时保持其功能不变。

src/hooks/useTouchMove.ts (1)

Line range hint 1-138: 总体评价:改动看起来是朝着正确的方向进行的。

这些更改针对性地解决了 Firefox 72.0 中标签滚动缓慢的问题,主要通过引入新的 getWheelDeltaOfPx 函数来计算滚轮增量值。这种方法可能提供了更一致的跨浏览器体验。

建议:

  1. 确保在多个浏览器版本(特别是 Firefox 72.0)中测试这些更改。
  2. 考虑添加注释,解释为什么需要这种特殊处理,以便将来的维护。
  3. 更新相关文档,说明这个修复解决的具体问题。
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 2fa1d36 and a4188a9.

📒 Files selected for processing (2)
  • src/hooks/useTouchMove.ts (2 hunks)
  • src/util.ts (2 hunks)
🔇 Additional comments (4)
src/util.ts (2)

1-1: 导入语句修改看起来没有问题。

这个修改似乎是为了适应新的TypeScript配置或React版本。它不会影响代码的功能。


Line range hint 1-43: 总结:这些更改很好地解决了PR的目标。

新添加的 isLineModegetWheelDeltaOfPx 函数直接针对了在某些Firefox版本(特别是72.0版本)中标签滚动缓慢的问题。通过将基于行的滚动转换为基于像素的滚动,这些更改应该能够改善滚动性能。

代码实现总体上是正确的,但有一些小的改进空间,主要是为了提高可读性和可维护性。建议在合并之前考虑实施这些改进。

src/hooks/useTouchMove.ts (2)

2-3: 导入语句的更改看起来不错。

导入语句的重新排序提高了可读性。新导入的 getWheelDeltaOfPx 函数表明滚轮增量值的计算方式发生了变化,这可能与修复 Firefox 72.0 中标签滚动缓慢的问题有关。


84-84: onWheel 函数的修改看起来是正确的方向。

使用 getWheelDeltaOfPx 函数来获取 deltaXdeltaY 的做法很好,这可能有助于解决 Firefox 72.0 中标签滚动缓慢的问题。这种方法可能提供了一种更一致的方式来计算不同浏览器的滚轮增量。

为了确保这个改动的有效性和兼容性,建议运行以下脚本来检查 getWheelDeltaOfPx 函数的实现:

这将帮助我们了解 getWheelDeltaOfPx 函数的实现细节和它在代码库中的使用情况,从而更好地评估这个改动的影响。

✅ Verification successful

为了解决之前的错误,请运行以下脚本以验证 getWheelDeltaOfPx 函数的使用情况:


onWheel 函数的修改已通过验证,未发现问题。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:验证 getWheelDeltaOfPx 函数的实现

# 测试:搜索 getWheelDeltaOfPx 函数的定义
echo "Searching for getWheelDeltaOfPx function definition:"
ast-grep --lang typescript --pattern $'function getWheelDeltaOfPx($_) {
  $$$
}'

# 测试:搜索 getWheelDeltaOfPx 函数的使用情况
echo "Searching for getWheelDeltaOfPx function usage:"
rg --type typescript 'getWheelDeltaOfPx'

Length of output: 805


Script:

# 描述:重新验证 getWheelDeltaOfPx 函数的使用情况

# 搜索 getWheelDeltaOfPx 函数的使用情况,限制为 .ts 文件
echo "Searching for getWheelDeltaOfPx function usage in .ts files:"
rg 'getWheelDeltaOfPx' -g "*.ts" -A 2

Length of output: 655

@afc163
Copy link
Member

afc163 commented Sep 29, 2024

这个问题在 Firefox 最新的版本中还存在么?如何重现?

Copy link

codecov bot commented Sep 29, 2024

Codecov Report

Attention: Patch coverage is 83.33333% with 2 lines in your changes missing coverage. Please review.

Project coverage is 97.47%. Comparing base (2fa1d36) to head (a4188a9).
Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
src/util.ts 81.81% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #658      +/-   ##
==========================================
- Coverage   97.72%   97.47%   -0.25%     
==========================================
  Files          18       18              
  Lines         702      713      +11     
  Branches      200      199       -1     
==========================================
+ Hits          686      695       +9     
- Misses         16       18       +2     

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

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.

2 participants