Skip to content

fix: full text content flashes before being truncated with <ol-read-more>#11812

Open
lokesh wants to merge 5 commits intointernetarchive:masterfrom
lokesh:fix/read-more-intial-render
Open

fix: full text content flashes before being truncated with <ol-read-more>#11812
lokesh wants to merge 5 commits intointernetarchive:masterfrom
lokesh:fix/read-more-intial-render

Conversation

@lokesh
Copy link
Collaborator

@lokesh lokesh commented Feb 4, 2026

fix: full text content flashes before being truncated with

Technical

Adds inline CSS in head.html to prevent flash of unstyled content for the ol-read-more custom element before its JavaScript definition runs.

Opted to use the visibility: hidden vs display: none as the browser may defer child content preparation if display none is used. Either solution probably fine though.

Testing

  1. Navigate to a page using ol-read-more (e.g., book description on an edition page, or search results with work descriptions)
  2. Open DevTools → Network tab → set throttling to "Slow 3G"
  3. Hard refresh the page (Cmd+Shift+R / Ctrl+Shift+R)

Screenshot

Fixed:
https://github.com/user-attachments/assets/313ac5b5-e212-4a2e-9f52-1c686ebbccf7

This change also fixes the flash of the 'Read more' button when it is not necessary. This issue is live on production:
https://github.com/user-attachments/assets/186afb95-7578-4356-ad09-f64f180fa13b

Stakeholders

@cdrini

@lokesh lokesh added the Theme: Design Issues related to UI design, branding, etc. [managed] label Feb 4, 2026
@lokesh lokesh requested a review from cdrini February 4, 2026 22:09
/* Hide ol-read-more content before component is defined to prevent flash of unstyled content */
ol-read-more:not(:defined) {
visibility: hidden;
height: 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main issue isn't the flash of unstyled content, but the cumulative layout shift, since the height will change while loading, causing all the items after it to change position. Setting the height to 0 here will still cause that issue. I think we might need to set the height explicitly in the element, eg <ol-read-more max-height="80px" style="max-height: 80px"> . Not satisfying, but let's us (1) decide the size at the moment the read-more is created, and (2) have it entirely avoid the layout shift.

Copy link
Collaborator Author

@lokesh lokesh Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, I updated the PR to set a min-height. Now just like production, there isn't a layout shift when the text is truncated. When the text is smaller then the defined height, just like production, there is a small layout shift, though in this updated version, the toggle button doesn't temporarily flash visible.

I also set defaults so that in most cases, you don't need to specify the max-height on the component or apply a min-height inline style.

Last change, I remove the max-lines property from the component. It was not being used and would introduce more complexity in terms of how we would resolve layout shifting.

…cation and updating default max-height

- Removed support for line-based truncation in the OLReadMore component.
- Updated documentation to clarify usage of height-based truncation with a default max-height of 80px.
- Adjusted related HTML templates to reflect changes in the component's attributes and styles for improved consistency.
@lokesh lokesh requested a review from cdrini February 5, 2026 20:43
Copy link
Collaborator

@cdrini cdrini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm, CLS is resolved! One small tweak to reduce the FOUC, and one question.

<h3>$_("Table of Contents")</h3>
$ component_times['TableOfContents'] = time()
<ol-read-more max-height="200px" more-text="$_('Read More')" less-text="$_('Read Less')">
<ol-read-more max-height="200px" style="min-height: 241px" more-text="$_('Read More')" less-text="$_('Read Less')">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit finnicky since we have to guesstimate the size of the read more button. We could potentially make the the readmore button position absolute inside the container? That way the max-height will define the full height of the component, including the read more button. Not a blocker.

Comment on lines 39 to 46
ol-read-more {
min-height: 121px;
overflow: hidden;
}
ol-read-more[label-size="small"] {
min-height: 107px;
}
</style>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait the CLS is still there! Should this max-height? And only defined for :not(:defined)? I found this CSS did the trick.

Suggested change
ol-read-more {
min-height: 121px;
overflow: hidden;
}
ol-read-more[label-size="small"] {
min-height: 107px;
}
</style>
ol-read-more:not(:defined) {
display: block;
max-height: 121px;
overflow: hidden;
}
ol-read-more[label-size="small"]:not(:defined) {
min-height: 107px;
}
</style>

cdrini and others added 2 commits February 6, 2026 12:00
Reverts the fallback style changes from 3acdaae and 2d8433d,
restoring the branch to the streamlined OLReadMore component state.

Co-authored-by: Cursor <cursoragent@cursor.com>
@lokesh
Copy link
Collaborator Author

lokesh commented Feb 6, 2026

Reverted back to f0f85c1

Limited layout shifting or flashing

@github-actions github-actions bot added the Needs: Response Issues which require feedback from lead label Feb 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs: Response Issues which require feedback from lead Theme: Design Issues related to UI design, branding, etc. [managed]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants