fix(animate): rework streaming animation into a staged reveal#531
Open
isaacwasserman wants to merge 2 commits into
Open
fix(animate): rework streaming animation into a staged reveal#531isaacwasserman wants to merge 2 commits into
isaacwasserman wants to merge 2 commits into
Conversation
Replace the per-word "animate newly-mounted words" model with a single
controller-driven reveal over a global, document-ordered segment space:
- Serialize sibling sections: exactly one chunk animates at a time across
all blocks, so a list finishes revealing before the next paragraph starts.
- Order every segment with the correct staggered delay, including rich/inline
content; atomic elements (code, images, math, embeds) reveal as a unit.
- Stable per-segment keys reconcile already-shown content in place instead of
remounting or re-animating it when the markdown re-parses mid-stream.
- Step the controller idempotently during render, so the reveal no longer
snaps under React StrictMode or concurrent rendering.
- Add `animated={{ reserveSpace: true }}` to fade segments in place without
layout shift instead of the default display:none collapse.
Internals live under lib/animate/ (transform, controller, plugin,
segment-counter, use-animation) with one consistent "animate" vocabulary.
Docs and tests updated; the public API (createAnimatePlugin, the animated
prop, data-sd-* attributes, sd-* keyframes) is unchanged.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
|
Someone is attempting to deploy a commit to the Vercel Team on Vercel. A member of the Team first needs to authorize it. |
The block segment counter was only rebuilt on animate-config changes, so a mid-stream change to the component/plugin set left it parsing a stale tree and returning stale cached counts — misaligning the global segment ordinals. Rebuild the counter (clearing its cache) whenever the config OR countingOptions identity changes. Also extract pure helpers (computeBaseOrdinals, toPerBlock, latchNow) to keep useAnimation under the cognitive-complexity limit, and add a regression test that drives the hook through a countingOptions change. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Description
Problem 1 (#482) — sections animated on top of each other. While a list was still
fading in, the next paragraph or heading would already start animating, so
several parts of the message were “alive” at once and the reveal felt chaotic.
Problem 2 — rich content animated out of order, or not at all. With
formatting like bold, italics, or links, often only the last word animated while
everything before it popped in instantly, so the reveal looked random.
Problem 3 — Despite animating in word-by-word, the layout (height of the markdown component) adjusts immediately, causing large amounts of chunkily growing foot space.
How it’s fixed:
ialways animates before sectioni+1, no matter when they were added to the queue.displayCSS property to prevent hidden segments from impacting layout.Type of Change
Related Issues
Fixes #482
Related to #493
Changes Made
ialways animates before sectioni+1, so sibling sections no longer animate at the same time.displayinstead of only fading opacity, so the component grows in step with the reveal instead of reserving the full height up front.animated={{ reserveSpace: true }}to keep the previous opacity-only behavior (reserve layout for unrevealed content).animatedprop,createAnimatePlugin, CSS classes/keyframes) is unchanged.Testing
Test Coverage
974 tests passing (77 files). New suites cover the reveal transform, the scheduler, an end-to-end streamed reveal, StrictMode/concurrent idempotency, and the
reserveSpacetoggle; the list re-animation regression test was rewritten for the new model.Screenshots/Demos
Checklist
pnpm changeset)Changeset
Additional Notes
animatedis enabled, content is wrapped in lightweight keyed spans that persist for stable reconciliation, and unrevealed text is collapsed withdisplay: noneby default (usereserveSpace: truefor the previous opacity-only layout). Inlinecodenow animates with the surrounding text.