fix(animate): serialize stagger delays across sibling blocks to prevent concurrent animation#493
fix(animate): serialize stagger delays across sibling blocks to prevent concurrent animation#493sleitor wants to merge 1 commit intovercel:mainfrom
Conversation
…nt concurrent animation Previously all blocks shared a single animate plugin instance with startIndex=0. When a new streaming block appeared, its words animated at delay=0 concurrently with the previous block's still-animating words. Fix: introduce AnimateCursor — a shared counter that resets to 0 before each render pass. Each block gets its own AnimatePlugin connected to the cursor; the plugin reads cursor.current as its startIndex, then increments the cursor by the number of newly animated words. This automatically chains stagger delays across all sibling blocks in render order. Also fixes the missing lastRenderNewWordCount update in the rehype closure. Closes vercel#482
|
@sleitor is attempting to deploy a commit to the Vercel Team on Vercel. A member of the Team first needs to authorize it. |
|
god bless your heart 💖 |
|
@sleitor Just curious if you had any rough estimate on when this change might get merged and released? The new animation that was added in 2.5 is really great but the parallel texts appearing at once makes it pretty unusable currently. Thanks! |
|
@ernieturner Thanks for the kind words, and completely agree — the parallel animation issue makes it hard to use in practice! This PR serializes stagger delays so each block completes its animation before the next one starts, which should resolve exactly what you're describing. Unfortunately I don't have visibility into the Vercel team's merge schedule, but hopefully your confirmation that this is a blocker will help nudge things forward. 🤞 In the meantime, if you're comfortable patching locally, the fix is in |
Summary
Fixes #482
When streaming markdown with multiple blocks, animations across sibling blocks revealed concurrently — a list could still be animating while the next paragraph was already fading in.
Root Cause
All blocks shared a single
AnimatePlugininstance with a fixedstartIndex=0. When a new block appeared, its first word started animating at delay=0ms, regardless of what was animating in the previous block.Additionally,
lastRenderNewWordCountwas never written back torenderStatein the rehype closure.Fix
Introduces
AnimateCursor— a lightweight shared counter ({ current: number }) that:0at the start of each React render pass (inStreamdown)AnimatePluginreadscursor.currentas itsstartIndexbefore animatingcursor.currentby the number of newly animated wordsThis chains stagger delays automatically across all sibling blocks in render order without any manual
setStartIndexwiring. Each block gets its ownAnimatePlugininstance soprevContentLengthtracking remains per-block independent.Changes
animate.ts: AddAnimateCursortype +createAnimateCursor(), addcursoroption tocreateAnimatePlugin(), fix missinglastRenderNewWordCountwriteindex.tsx: Replace single shared plugin with per-block plugins array + shared cursor; extractgetBlockPlugins()helper to stay within biome complexity limitsanimate.test.ts: Add 4 cursor chaining tests (36 tests total, all passing)