-
Notifications
You must be signed in to change notification settings - Fork 322
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: remove redundant overflow style manipulation #2678
Conversation
const curOverflow = element.style.overflow; | ||
if (!curOverflow || curOverflow === "visible") element.style.overflow = "hidden"; |
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 probably intended for more accurate calculation but it triggers a redraw which makes this function heavy
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.
when you say more accurate, what are we "losing" here? only legacy browsers?
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.
In modern browsers, elements can have overflow
styles like visible
, hidden
, auto
, or scroll
, which control how content is displayed when it exceeds the container's dimensions. Historically (2017<), and in some edge cases even today, browsers have had quirks in how they calculate scrollWidth
and scrollHeight
when overflow
is set to visible:
overflow: visible
Behavior:- When
overflow
isvisible
, the browser does not clip or restrict content, soscrollWidth
andscrollHeight
might not accurately represent the "overflowing" content dimensions. - Some older browsers would inconsistently calculate the
scrollHeight
orscrollWidth
, leading to unreliable results. For example:- If the content extended outside the container,
scrollHeight
might only reflect the visible portion of the element.
- If the content extended outside the container,
- When
- Dynamic Overflow Calculations:
- Some browsers historically recalculated layout properties like
scrollHeight
andscrollWidth
lazily or only whenoverflow
was set tohidden
,auto
, orscroll
. As a result, developers often had to temporarily setoverflow
to force the browser to update these values.
- Some browsers historically recalculated layout properties like
- Rendering Engine Differences:
- Older rendering engines (e.g., Trident in Internet Explorer or older versions of WebKit) had subtle bugs in handling overflow. Developers would use workarounds like temporarily changing the
overflow
property to get consistent values.
- Older rendering engines (e.g., Trident in Internet Explorer or older versions of WebKit) had subtle bugs in handling overflow. Developers would use workarounds like temporarily changing the
The approach of temporarily setting overflow: hidden
is a deliberate attempt to work around these historical inconsistencies. Now, it assumes that these historical quirks do not apply or that the overflow
property is already managed correctly. In modern browsers, the need for such workarounds has significantly decreased. The major benefit is the dramatic performance improvement
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.
fair enough
A new prerelease version of this PR has been published! 🎉 To update
Or with npm:
|
https://monday.monday.com/boards/3532714909/pulses/8113296723