-
Notifications
You must be signed in to change notification settings - Fork 87
fix: Use requestAnimationFrame with ResizeObserver #10282
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
base: main
Are you sure you want to change the base?
Conversation
Modified ResizeObserver to use requestAnimationFrame for better performance in Safari.
|
web-padawan
left a comment
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.
Is there any particular case where you were able to observe performance problems? If so, please create an issue first. I understand that it might be difficult to cover the change with a unit test but ideally we would have at least a test to cover timings change.
| // Use requestAnimationFrame to avoid performance issues with Safari | ||
| this.__resizeObserver = new ResizeObserver(() => { | ||
| const ironListAdapter = this; | ||
| requestAnimationFrame(() => ironListAdapter._resizeHandler()); |
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.
A debouncer would be preferable here, since it also eliminates unnecessary resize handler calls
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.
Yes, that would work too.
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.
Calling _resizeHandler right inside the ResizeObserver callback has performance advantages. Layout is already computed at that stage, but the frame hasn't been painted, so reading such properties as scrollWidth or using getComputedStyle shouldn't generally cause a reflow as long as the layout has not been dirtied again. We will lose this benefit if _resizeHandler is deferred until the next frame.
Also, delaying _resizeHandler to the next frame may not fix the issue and could just make it asynchronous.
We need a reproducible example to confirm that this change actually fixes the issue.



Modified ResizeObserver to use requestAnimationFrame for better performance in Safari.