Investigate possibility of creating API, CSS class, reusable animation to help eliminate page jank

Created on 26 April 2024, 12 months ago

This is split off from ๐ŸŒฑ META: Reduce / eliminate โ€œjankโ€ (layout shifts) within Drupalโ€™s admin UI Active but originates as a discussion on ๐Ÿ› Views UI action buttons create janky layout shift on page load Needs work 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.

๐Ÿ“Œ Task
Status

Active

Version

11.0 ๐Ÿ”ฅ

Component
CSSย  โ†’

Last updated 10 days ago

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States mherchel Gainesville, FL, US

Live updates comments and jobs are added and updated live.
  • CSS

    It involves the content or handling of Cascading Style Sheets.

Sign in to follow issues

Comments & Activities

  • Issue created by @mherchel
  • ๐Ÿ‡ซ๐Ÿ‡ทFrance nod_ Lille

    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

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States mherchel Gainesville, FL, US

    Maybe for the js-hide class we could use the media query to make sure we hide things asap.

    We already got that committed in ๐Ÿ› Table filter creates jank (layout shift) on page load Fixed . See https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/syste...

  • Here'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.

    img, iframe {
      min-width: 100px;
      min-height: 100px;
      aspect-ratio: 16/9;
    }
    
    
    Font Loading: Use font-display: swap to avoid layout shifts caused by late-loading fonts.
    @font-face {
      font-display: swap;
    }
    

    Smooth Animations: Apply fade-in animations for dynamically loaded content to avoid sudden jumps.

    .dynamic-content {
      opacity: 0;
      transition: opacity 0.3s ease-in-out;
    }
    .dynamic-content.loaded {
      opacity: 1;
    }

    2. JS Fix:
    Add a loaded class to dynamically added elements after the page loads to trigger smooth transitions.

    document.addEventListener('DOMContentLoaded', () => {
      document.querySelectorAll('.dynamic-content').forEach(el => el.classList.add('loaded'));
    });

    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!

Production build 0.71.5 2024