-
Notifications
You must be signed in to change notification settings - Fork 65
-
Notifications
You must be signed in to change notification settings - Fork 65
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
Infinite loop in Truncate
#1797
Labels
Comments
@viktorrusakov, I see you'll soon start working on Truncate v3. Can we take this issue in consideration during its development? |
arbrandes
pushed a commit
to arbrandes/frontend-app-discussions
that referenced
this issue
Nov 25, 2022
This works around [a known issue](openedx/paragon#1797) with `Truncate` that in some situations can lead to an infinite loop and subsequent page hang.
arbrandes
pushed a commit
to arbrandes/frontend-app-discussions
that referenced
this issue
Nov 28, 2022
This works around [a known issue](openedx/paragon#1797) with `Truncate` that in some situations can lead to an infinite loop and subsequent page hang.
arbrandes
pushed a commit
to arbrandes/frontend-app-discussions
that referenced
this issue
Nov 28, 2022
This works around [a known issue](openedx/paragon#1797) with `Truncate` that in some situations can lead to an infinite loop and subsequent page hang.
arbrandes
pushed a commit
to openedx/frontend-app-discussions
that referenced
this issue
Nov 28, 2022
This works around [a known issue](openedx/paragon#1797) with `Truncate` that in some situations can lead to an infinite loop and subsequent page hang.
@arbrandes working on it, thanks for reporting the issue! |
22 tasks
10 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As of this revision,
Truncate
assumes that thescrollHeight
of an unpadded element containing only text will be an exact multiple of itsline-height
property:This assumption is incorrect. Independently of a parent element's
line-height
, if a child inline element is vertically aligned tobaseline
(the default), it is possible for the parent'sscrollHeight
to be greater than the sum of the heights of all lines it contains. This is because the browser will pad each line's box vertically with enough space for a font's descenders with a value that varies according to font, browser zoom level, etc.In particular, consider this usage of
Truncate
, where a single line is desired across three inner<span />
s. No matter what value ofline-height
is set for the parent, it was observed in at least two browser implementations (Firefox 107.0 (64-bit) and Chromium 107.0.5304.121 (64-bit), both on Ubuntu Linux 22.04.1) that when finally truncated to one line,visibilityArea
would always be one pixel larger thannewElement.scrollHeight
, leading to an infinite loop.A workaround, as suggested here, is to
vertical-align: bottom
all child<span />
s so they conform to the parent'sline-height
. In practice, this successfully avoids the infinite loop because when its down to a single line,newElementTextHeight
will finally be equal to the expectedvisibilityArea
.Truncate
should be smart enough to avoid this without any expectations regarding the vertical alignment of child elements.(Nowadays browsers actually support CSS-only line clamping, so
Truncate
might optionally use that. Clamp.js, for example, checks for support and uses it, if enabled.)The text was updated successfully, but these errors were encountered: