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

Perf: Use getComputedStyle( node ).opacity instead of node.scrollTop to force repaint #892

Open
rejhgadellaa opened this issue Sep 3, 2023 · 0 comments

Comments

@rejhgadellaa
Copy link

rejhgadellaa commented Sep 3, 2023

The forceReflow() function in src/utils/reflow.js currently reads node.scrollTop to force a reflow. That causes style, layout, paint and composite to be run (and makes sure the browser picks up on style changes that need a transition), but there is a shortcut that only causes style recalculation without doing layout and paint (at least not until the next frame is requested:

getComputedStyle( node ).opacity

It would also help if the style of the (container) element is contained (e.g., something like contain: content;) so the browser can optimize which part of the style needs to recalculate). I guess that depends on the use-case but may be worth mentioning in the docs?

See this blog post (or skip straight to relevant code snippet)

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

No branches or pull requests

1 participant