-
-
Notifications
You must be signed in to change notification settings - Fork 589
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
fix: dynamic sticky #1184
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Walkthrough更改涉及 Changes
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configuration File (
|
There was a problem hiding this 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
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
:isSticky
在useMemo
的依赖数组中。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
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
插个题外话。
可以指个路么,想看看具体代码位置 |
There was a problem hiding this 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
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
从这里开始看,scroll.y 或 sticky 时,表头是单独的 Table,会使用这里的 colWidths, 但是一开始是空的,所以会造成闪烁的问题。是因为渲染后,measureCell (包了 ResizeObserver)才能用 onColumnResize 方法收集宽度 |
在table上设置了sticky默认false, 加载完后true, 没有解决问题 |
@wowtrxqn antd 还没发版,要等 5.21.0 |
好的,谢谢 |
刚更新了5.21.0测了下, 没修复成功 |
我试了下,应该可以啊。你把重现地址发出来看看 |
我用的是<EditableProTable .../> |
|
@wowtrxqn 打不开,加点 setTimeout hack 下试试吧。Table 大佬在重构了,完全解决要等等 |
https://stackblitz.com/edit/react-mpsdjq-1nu1jh?file=demo.tsx |
@wowtrxqn 我现在是这么解决的:表头强制一行,用动画 0.01s 后展示。用 js 也可以,useEffect 里设置 visibility 或 opacity
|
这样可以解决, 谢谢 |
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
钩子的实现,减少不必要的重新计算,提高了性能。