Skip to content

fix: keep looping async chains alive after a declarative reissue - #2661

Closed
charan-rathore wants to merge 1 commit into
pmndrs:nextfrom
charan-rathore:fix/async-loop-chain-reissue
Closed

charan-rathore wants to merge 1 commit into
pmndrs:nextfrom
charan-rathore:fix/async-loop-chain-reissue

Conversation

@charan-rathore

Copy link
Copy Markdown
Contributor

Why

Resolves #2095

A spring with loop: true and an async to sequence stops looping when a
declarative render reissues the same props mid-sequence, for example when the
consuming element mounts late. The animation plays once and then goes idle
instead of looping.

What

In flushUpdate, loop continuation after an async to chain is now decided
by the chain's own result, not by the combined result of every promise in the
update.

The combined result also covers the per-key preparation updates, which carry
no to of their own. When a reissue lets the new chain's steps interrupt
them, they settle with finished: false, which only means they were replaced
by their own successor. Treating that as "the chain did not finish" wrongly
vetoes the loop.

The combined result still governs the returned promise and onResolve. In
the tested bounded case (a reissued chain with a finite loop count), that
promise resolves finished: true once the replacement chain completes, where
the stalled base resolved finished: false. That outcome change is the
intended effect of the fix. An unbounded loop keeps running until an explicit
stop or cancel, unchanged.

Explicit stops are unchanged: stop(true), global stop(), and the cancel
prop still end the loop exactly as before.

One deliberate behavior change beyond the stall fix: stopping a single key
without cancel (ctrl.stop(false, 'width')) during a reissued chain now
behaves the same as it already did for a chain that was never reissued - the
chain keeps looping, because a key-level stop never cancelled the async chain.
Before this change, a reissued chain would stall entirely instead. Global
stops and true cancels are untouched.

New regression tests: 8 asserted cases covering reissue during the first and
second sequence steps, cancellation, pause and resume, and an explicit
loop: false override. A further 11 observational cases record the existing
stop semantics on both sides of the change (base and patched), confirming
which behaviors moved and which did not.

Validation

Official repository tree at the current next head (83e4760), pnpm frozen
lockfile, Node 24, pnpm 12.14.0, Vitest browser mode with Chromium 156,
TypeScript 7.0.2:

  • pnpm build: 9/9 tasks.
  • Whole-repo tsc --noEmit: 0 errors (run after build, per repo ordering).
  • pnpm lint: 0 errors, 95 warnings, identical to the unpatched baseline.
  • Full unit project: 430/430 pass (411 baseline + 19 added).
  • The three changed-area test files: 19/19 pass with the patch; the same
    files on the unpatched base give 2 failures / 17 passes, and the 2 failures
    are the loop-stall regressions.

Not run: the documentation site build and demos (no docs or demo changes in
this PR). No public API or dependency changes.

Checklist

  • Documentation updated (no docs changes in this PR)
  • Demo added (no demo changes in this PR)
  • Ready to be merged

Loop continuation after an async to chain is now decided by the chain's
own result instead of the combined result of every promise in the update.
The per-key preparation updates settle with finished: false when a reissue
lets the new chain interrupt them, which previously vetoed the loop and
stopped the animation after its first pass. The combined result still
governs the returned promise and onResolve.

Resolves pmndrs#2095
@changeset-bot

changeset-bot Bot commented Nov 20, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 24546d6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 8 packages
Name Type
@react-spring/core Patch
@react-spring/animated Patch
@react-spring/parallax Patch
@react-spring/rafz Patch
@react-spring/shared Patch
@react-spring/types Patch
@react-spring/three Patch
@react-spring/web Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@joshuaellis

Copy link
Copy Markdown
Member

Respectfully, have you actually looked at anything you've just submitted here? Or did you just open the PR after AI wrote the code?

@joshuaellis

Copy link
Copy Markdown
Member

thanks for finding where this goes wrong. the loop decision in flushUpdate reading the combined result is the right place, and i've opened #2674 to fix it there, so i'm going to close this one.

#2674 goes one step further: for an async to, the update's whole result comes from the chain, not just the loop decision. so a re-rendered sequence without loop also resolves finished: true once it completes, instead of false. it also keeps a reference to the chain's promise rather than relying on it being the last one pushed.

for next time:

  • run the repo's checks before opening the PR. all three new test files fail oxfmt --check, so CI would have failed straight away.
  • make every test assert something. Controller.issue2095Stops.test.ts only prints console.warn output, so it can never fail, and it fills the test log.
  • put tests in their module's existing file (Controller.test.ts) rather than new files named after the issue.
  • once you've found the cause, check what else reads the same value. here the same result also feeds onResolve and the returned promise, and they had the same bug.
  • keep the description to what the user sees and why it happened. the diff covers the rest.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug]: animation does not loop if consumer element takes to long to appear

2 participants