This is split off from #3404214: META: Reduce / eliminate “jank” (layout shifts) within Drupal’s admin UI but originates as a discussion on #3441124: Views UI action buttons create janky layout shift on page load where @nod_ suggested trying to abstract out the method of reducing jank into something more reusable (such as a CSS class). We've also had discussions in Slack at https://drupal.slack.com/archives/C1BMUQ9U6/p1714158882541689
I'm not entirely sure this is possible or worth it, as the cause of the jank issues are many. But, there may be opportunity here if the same cause affects multiple places.
I'm leaving this here as a placeholder to see if once we get some of these fixes into core, patterns can emerge and we can re-evaluate.
Comments
Comment #2
nod_Maybe for the js-hide class we could use the media query to make sure we hide things asap. Would be good to try it out see if that helps some UI
Comment #3
mherchelWe already got that committed in #3404218: Table filter creates jank (layout shift) on page load. See https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/syste...
Comment #4
saurav-drupal-dev commentedHere's a quick approach to tackle page jank:
1. CSS Fixes:
Reserve Space for Content: Use min-width, min-height, or aspect-ratio for images and iframes to prevent layout shifts.
Smooth Animations: Apply fade-in animations for dynamically loaded content to avoid sudden jumps.
2. JS Fix:
Add a loaded class to dynamically added elements after the page loads to trigger smooth transitions.
3. Drupal Setup:
Add the CSS/JS to a custom module or theme to apply across pages.
4. Testing:
Monitor metrics like Cumulative Layout Shift (CLS) to ensure improvements.
Let me know what you think!