fix(animate): serialize stagger delays across sibling blocks to prevent concurrent animation#493
Open
sleitor wants to merge 1 commit intovercel:mainfrom
Open
fix(animate): serialize stagger delays across sibling blocks to prevent concurrent animation#493sleitor wants to merge 1 commit intovercel:mainfrom
sleitor 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
Contributor
|
@sleitor is attempting to deploy a commit to the Vercel Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)