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: dynamic sticky #1184

Merged
merged 2 commits into from
Aug 28, 2024
Merged

Conversation

linxianxi
Copy link
Contributor

@linxianxi linxianxi commented Aug 28, 2024

sticky 可以动态,这个合并后。

在自己的应用中先设置 sticky 为 false,渲染后再设置为 true,虽然比较 hack,但可以暂时在应用层中解决 Header 闪烁的问题 ant-design/ant-design#50496

(因为目前没有很好的方式解决,因为 rc-table 中有 scroll.y 或 sticky 时,表头是单独的 Table,表头的宽度收集是用的表 body 的 MeasureCell (包了 ResizeObserver,onResize 触发会慢一拍)。

Summary by CodeRabbit

Summary by CodeRabbit

  • 性能提升
    • 优化了 useSticky 钩子的实现,减少不必要的重新计算,提高了性能。

Copy link

vercel bot commented Aug 28, 2024

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

Name Status Preview Comments Updated (UTC)
table ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 28, 2024 8:58am

Copy link

coderabbitai bot commented Aug 28, 2024

Walkthrough

更改涉及 useSticky 钩子的 isSticky 变量的定义和使用。isStickyuseMemo 钩子中移出,改为在函数执行时计算一次,避免了不必要的重复计算。依赖数组也进行了更新,以确保在 isSticky 更改时重新计算缓存值。

Changes

文件路径 更改摘要
src/hooks/useSticky.ts 修改 isSticky 的定义位置及依赖数组,提升性能。

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between bedfc01 and 6e906b2.

Files selected for processing (1)
  • src/hooks/useSticky.ts (2 hunks)
Additional comments not posted (2)
src/hooks/useSticky.ts (2)

29-30: 优化了性能。

isSticky 的计算从 useMemo 中移出,可以有效减少不必要的重计算,从而提高性能。

代码更改已通过审核。


40-40: 验证动态粘性功能的正确性。

请确保 isSticky 的变化能正确触发 useMemo 的重新计算,以保持粘性功能的动态性。

运行以下脚本以验证动态粘性功能的正确性:

Verification successful

验证动态粘性功能的正确性已确认。

useSticky.ts 文件中,isSticky 被正确地包含在 useMemo 的依赖数组中,这意味着当 isSticky 发生变化时,会触发重新计算,从而确保粘性功能的动态性。其他文件中的使用也表明 isSticky 在粘性功能的上下文中被正确应用。

  • src/hooks/useSticky.ts: isStickyuseMemo 的依赖数组中。
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:验证动态粘性功能的正确性。

# 测试:搜索 `isSticky` 的使用情况。预期:只有新的签名出现。
rg --type typescript -A 5 $'isSticky'

Length of output: 71


Script:

#!/bin/bash
# Corrected script to search for `isSticky` usage in TypeScript files.

# Search for `isSticky` in TypeScript files to verify its usage.
rg --type ts -A 5 $'isSticky'

Length of output: 6678

Copy link

codecov bot commented Aug 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.70%. Comparing base (bedfc01) to head (36a4013).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1184   +/-   ##
=======================================
  Coverage   97.70%   97.70%           
=======================================
  Files          75       75           
  Lines        7417     7417           
  Branches     1112     1112           
=======================================
  Hits         7247     7247           
  Misses        164      164           
  Partials        6        6           

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

src/hooks/useSticky.ts Outdated Show resolved Hide resolved
src/hooks/useSticky.ts Outdated Show resolved Hide resolved
@Wxh16144
Copy link
Contributor

插个题外话。

表头的宽度收集是用的 ResizeObserver

可以指个路么,想看看具体代码位置

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6e906b2 and 36a4013.

Files selected for processing (1)
  • src/hooks/useSticky.ts (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/hooks/useSticky.ts

@afc163 afc163 merged commit 934448a into react-component:master Aug 28, 2024
8 checks passed
@linxianxi
Copy link
Contributor Author

linxianxi commented Aug 28, 2024

插个题外话。

表头的宽度收集是用的 ResizeObserver

可以指个路么,想看看具体代码位置

这里开始看,scroll.y 或 sticky 时,表头是单独的 Table,会使用这里的 colWidths, 但是一开始是空的,所以会造成闪烁的问题。是因为渲染后,measureCell (包了 ResizeObserver)才能用 onColumnResize 方法收集宽度

@wowtrxqn
Copy link

sticky 可以动态,这个合并后。

在自己的应用中先设置 sticky 为 false,渲染后再设置为 true,虽然比较 hack,但可以暂时在应用层中解决 Header 闪烁的问题 ant-design/ant-design#50496

(因为目前没有很好的方式解决,因为 rc-table 中有 scroll.y 或 sticky 时,表头是单独的 Table,表头的宽度收集是用的表 body 的 MeasureCell (包了 ResizeObserver,onResize 触发会慢一拍)。

Summary by CodeRabbit

Summary by CodeRabbit

  • 性能提升

    • 优化了 useSticky 钩子的实现,减少不必要的重新计算,提高了性能。

在table上设置了sticky默认false, 加载完后true, 没有解决问题

@linxianxi
Copy link
Contributor Author

@wowtrxqn antd 还没发版,要等 5.21.0

@wowtrxqn
Copy link

@wowtrxqn antd 还没发版,要等 5.21.0

好的,谢谢

@wowtrxqn
Copy link

@wowtrxqn antd 还没发版,要等 5.21.0

刚更新了5.21.0测了下, 没修复成功

@linxianxi
Copy link
Contributor Author

@wowtrxqn antd 还没发版,要等 5.21.0

刚更新了5.21.0测了下, 没修复成功

const [sticky, setSticky] = useState(false);

  useEffect(() => {
    setSticky(true);
  }, []);

我试了下,应该可以啊。你把重现地址发出来看看

@wowtrxqn
Copy link

@wowtrxqn antd 还没发版,要等 5.21.0

刚更新了5.21.0测了下, 没修复成功

const [sticky, setSticky] = useState(false);

  useEffect(() => {
    setSticky(true);
  }, []);

我试了下,应该可以啊。你把重现地址发出来看看

我用的是<EditableProTable .../>

@wowtrxqn
Copy link

wowtrxqn commented Sep 23, 2024

@wowtrxqn antd 还没发版,要等 5.21.0

刚更新了5.21.0测了下, 没修复成功

const [sticky, setSticky] = useState(false);

  useEffect(() => {
    setSticky(true);
  }, []);

我试了下,应该可以啊。你把重现地址发出来看看

https://react-mpsdjq-1nu1jh.stackblitz.io

@linxianxi
Copy link
Contributor Author

@wowtrxqn 打不开,加点 setTimeout hack 下试试吧。Table 大佬在重构了,完全解决要等等

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.

4 participants