Skip to content

fix(statechart, overmind): await async exit actions, fix devtools actions, fix throttle stale value#655

Merged
ericsorenson merged 1 commit intonextfrom
state-chart-fixes
Apr 4, 2026
Merged

fix(statechart, overmind): await async exit actions, fix devtools actions, fix throttle stale value#655
ericsorenson merged 1 commit intonextfrom
state-chart-fixes

Conversation

@ericsorenson
Copy link
Copy Markdown
Collaborator

Summary

  • Fix statechart exit actions not being awaited when async, breaking exit → action → transition → entry ordering
  • Fix devtools incorrectly showing onInitializeOvermind as a transition action after state changes
  • Fix throttle operator passing the first invocation's value instead of the most recent one

Bug Fixes

1. Statechart: async exit actions not awaited before transitions

When a statechart exit action was async (plain async function or operator-based via pipe), the returned
Promise was discarded. The main action, state transition, and entry actions executed immediately without
waiting for exit to complete.

The runAction wrapper now collects exit action return values, detects Promises via isPromise, and
Promise.all()s them before proceeding. After async exits complete, it re-validates the transition is
still valid since another action may have changed state during the async gap. The synchronous code path
is unchanged.

2. Statechart: wrong actions object passed to devtools

After a state transition, the devtools update used config.actions (which includes onInitializeOvermind)
instead of copiedActions (which has it removed). The other two call sites already used copiedActions
correctly.

3. Throttle operator passes stale value

The throttle operator's setTimeout closure captured value from the first invocation. Subsequent calls
updated currentNext but not the value inside the already-scheduled timeout. Added a currentValue
variable updated on every invocation so the timeout fires with the most recent value.

Other Changes

  • Exported isPromise from overmind's public API so overmind-statechart can import it instead of
    duplicating the implementation
  • Added 6 new statechart tests covering operator-based actions and async exit ordering
  • Added 1 new throttle test verifying the most recent value is passed downstream

@codesandbox
Copy link
Copy Markdown

codesandbox Bot commented Mar 28, 2026

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@ericsorenson ericsorenson marked this pull request as ready for review March 28, 2026 18:06
Copy link
Copy Markdown
Member

@henri-hulski henri-hulski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! Good you take a look at statecharts, another package which didn't get much care.

BTW if you fix different task in a PR you can use several commits. One commit is one entry in the release notes (which replaces the changelog). So for every entry in the release notes you need to create a separate commit.

@ericsorenson ericsorenson merged commit e174b92 into next Apr 4, 2026
8 checks passed
@ericsorenson ericsorenson deleted the state-chart-fixes branch April 4, 2026 15:35
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.

2 participants