Skip to content

Weird auto-animation when using gap property #70

Closed

Description

@paoloricciuti

If you use gap property on a grid or a flexbox and try to auto-animate a remove it weirdly jumps around.

Here's a reproduction in codepen: https://codepen.io/paoloricciuti/pen/YzaRyNV

Activity

  1. justin-schroeder commented on Aug 19, 2022

    @justin-schroeder
    Member

    There are a few css properties that appear to require a "double paint" at the browser rendering engine level — when the mutation observer gets fired, only 1 of the two has happened. There are some flex layouts and table layouts that also do the same thing. I'm sure what the solution is to these issues but open to suggestions.

  2. patrikzudel commented on Apr 12, 2023

    @patrikzudel

    It would be amazing if someone would have a list of CSS properties / layout patterns that lead to double painting. I am encountering these jumps when using more complex objects / layouts and its a shame. Finding a fix or a workaround would be amazing!

  3. clicktodev commented on May 1, 2025

    @clicktodev

    is there a theoretical solution to the double paint problem?
    this kinda sucks, the library in unusable with flex and grid

  4. justin-schroeder commented on May 1, 2025

    @justin-schroeder
    Member

    If you find a solution im all ears

  5. clicktodev commented on May 6, 2025

    @clicktodev

    can you provide more info on the "double paint' behavior?

  6. justin-schroeder commented on Nov 22, 2026

    @justin-schroeder
    Member

    Dug into this one properly 🔬 I sampled element positions every 200ms through a remove in flex + gap, grid + gap and wrapping flex: on current AutoAnimate (0.10.x) they all glide smoothly with no jumps, so the original gap case is fixed.

    The jump that remains is items that stretch (flex: 1 / flex-grow). Removing a sibling makes every item wider (85px → 120px in my test). AutoAnimate does emit width keyframes, but flex: 1 sets flex-basis: 0%, so width is ignored and the items snap to their new size. That's the "double paint" feeling. Animating flex-basis instead doesn't save it: as items resize, the layout reflows every frame while FLIP transforms are computed against the final layout, so neighbours slide twice. Fixing that properly needs per-frame position correction (a much bigger change), so it isn't happening in a patch.

    Workaround, now in the docs (#259): give items a fixed basis (flex: 0 0 120px) or use a grid with fixed tracks, and everything animates cleanly. Closing as fixed for gap, with the stretch limitation documented. If anyone has a layout with fixed-size items that still jumps, please post a repro! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions