Layout

Motion · Next.js

A cart drawer that keeps up

Change a quantity or remove a piece, and the lines below close up at once, before the store has answered.

With Wardic: Solid 1 · Solid 2

Live demo

Your cart lives on the store: what you add here is in the header's cart too.

Reduced motion: The drawer appears in place and the lines close up at once; the fades stay.

Beside Wardic

React 19's useOptimistic lays the changes on their way over the store's lines, as Solid 2's optimistic store does (Solid 1 reads the router's pending submissions). Motion's version needs a LayoutGroup around the drawer's body: when "Your cart is empty" goes at the end of its fade, nothing there renders again, and Motion measures a layout element as it renders, so the suggestions would jump up into its space; Wardic sees their box change, and glides them. And a change is a server action that calls refresh(), which reads the cart again with everything else on the page.

The code

Highlighting…