fix(core): parallel top-level transitions preserve sibling region sub-state - #5564
Open
JSap0914 wants to merge 1 commit into
Open
fix(core): parallel top-level transitions preserve sibling region sub-state#5564JSap0914 wants to merge 1 commit into
JSap0914 wants to merge 1 commit into
Conversation
When a transition is defined directly on a parallel state (in its `on` property) and targets a specific sub-region, the other parallel regions were incorrectly reset to their initial sub-states. Root cause: `computeExitSet` was exiting ALL descendants of the parallel domain, and `computeEntrySet` was pushing the domain into the ancestor list which caused `addAncestorStatesToEnter` to add every sibling region via `addDescendantStatesToEnter` (starting from initial). Fix: when the transition's source IS the parallel domain and no target is the domain itself, scope the exit set to only the regions that contain the targets, and skip pushing the domain into ancestors so sibling regions are not re-entered from scratch. Cross-region transitions (source is a child state, not the domain) and full-reset transitions that target the domain node itself continue to work as before. Fixes statelyai#5214
🦋 Changeset detectedLatest commit: c0970e2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
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 #5214
Bug
When a transition is defined directly on a parallel state (its
onproperty) and targets a specific sub-region, all other parallel regions were being reset to their initial sub-states.Root Cause
In
computeExitSet, when the transition domain is a parallel state, ALL active descendants of that domain were added to the exit set — including states in unrelated sibling regions.In
computeEntrySet, the domain (parallel state) was pushed into the ancestor list, which causedaddAncestorStatesToEnterto calladdDescendantStatesToEnterfor every child of the parallel state not already targeted, resetting them to their initial sub-states.Fix
When the transition's source IS the parallel domain and no target is the domain itself:
computeExitSet: only adds states in the parallel regions that contain the transition targets to the exit set. Sibling regions are left untouched.computeEntrySet: skips pushing the parallel domain into ancestors, soaddAncestorStatesToEnternever resets sibling regions.Cross-region transitions (source is a child state, not the domain) and full-reset transitions that target the domain node itself (e.g.
RESET: '#machineId') continue to work with the original behaviour.Verification
New regression test: "transitions defined on a parallel state should not reset sibling regions to their initial sub-state" in
packages/core/test/parallel.test.ts.