-
-
Notifications
You must be signed in to change notification settings - Fork 261
fix: add requestAnimationFrame to resizeObserver(#23956); #319
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #319 +/- ##
==========================================
- Coverage 93.84% 93.39% -0.46%
==========================================
Files 11 11
Lines 813 818 +5
Branches 236 236
==========================================
+ Hits 763 764 +1
- Misses 50 54 +4
Continue to review full report at Codecov.
|
src/DOMWrap.tsx
Outdated
|
|
||
| componentDidMount() { | ||
| this.setChildrenWidthAndResize(); | ||
| this.setChildrenWidthAndResize = debounce( |
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.
组件卸载的时候要清除掉副作用。
src/DOMWrap.tsx
Outdated
| componentDidMount() { | ||
| this.setChildrenWidthAndResize(); | ||
| this.setChildrenWidthAndResize = throttle( | ||
| this.setChildrenWidthAndResize, |
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.
这个写法有点奇怪,不要覆盖 this.setChildrenWidthAndResize。
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.
想了一下不要用 throttle,直接上 requestAnimationFrame 就行了。
|
测试失败了,我看看。 |
| cancelAnimationFrame(cancelFrameId); | ||
| this.cancelFrameId = requestAnimationFrame( | ||
| this.setChildrenWidthAndResize, | ||
| ); |
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.
记得在 componentWillUnmount 里 cancelAnimationFrame 掉。
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.
这样写性能提升效果如何?
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.
OK
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.
这样写了后效果可以,和节流的效果差不多,就是从整个菜单隐藏到显示时,最后的...按钮还是会闪一下(延迟出现)。
|
用了 |
可以试试,不过我担心还是会影响性能。 |
我试了,得加上,不然初始化的时候就会闪一下。 |
|
这个怎么覆盖测试,想了半天不知道怎么写? |
|
可能要 |
const { cancelFrameId } = this;
cancelAnimationFrame(cancelFrameId);
this.cancelFrameId = requestAnimationFrame(
this.setChildrenWidthAndResize,
);这段怎么覆盖呢?我想着是检测 |
|
@afc163 这个咱们怎么弄呢?现在我的改动和效果就是我发的那样,就是新加的那几行测试覆盖不到。 |
|
不好测先跳过好了 |
|
谨慎起见,我发了 8.2.0,到 antd 里升级一下测试。 |
OK, 更新后建议你也先在本地看看效果有什么问题 |
|
npm 貌似没法发布。。 |
有什么问题? |
|
npm 挂了。 |
|
可以了,已发布。 |
|
给 antd 发 PR 吧 |



#23956
目前加的防抖时间是100毫秒。