Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed an issue with some exit handlers being executed more than once when stopping a machine #2895

Merged
merged 1 commit into from
Dec 27, 2021

Conversation

Andarist
Copy link
Member

No description provided.

@changeset-bot
Copy link

changeset-bot bot commented Dec 27, 2021

🦋 Changeset detected

Latest commit: 74ae6b2

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

This PR includes changesets to release 1 package
Name Type
xstate 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

@ghost
Copy link

ghost commented Dec 27, 2021

CodeSee Review Map:

Review these changes using an interactive CodeSee Map

Review in an interactive map

View more CodeSee Maps

Legend

CodeSee Map Legend

Comment on lines -994 to -999
if (!transition.source) {
transition.exitSet = [];

// Ensure that root StateNode (machine) is entered
transition.entrySet.push(this);
}
Copy link
Member Author

Choose a reason for hiding this comment

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

this was redundant as in this scenario (when there is no transition.source - which in turn means "when resolving the initial state") because the exitSet is already empty and nothing pushes to it AND entrySet is already resolved with this in it - so we were always adding a duplicate root to the list here

Comment on lines -676 to -678
const subStateNodes: Array<
StateNode<TContext, any, TEvent, TTypestate>
> = subStateKeys.map((subStateKey) => this.getStateNode(subStateKey));
Copy link
Member Author

Choose a reason for hiding this comment

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

Similarly here - the logic that follows this is already pushing this.getStateNode(subStateKey) to the subStateNodes so this line here could be dropped to avoid duplicate entries being pushed to the final subStateNodes

Comment on lines +680 to 686
subStateNodes.push(
...flatten(
subStateKeys.map((subStateKey) =>
this.getStateNode(subStateKey).getStateNodes(stateValue[subStateKey])
)
)
);
Copy link
Member Author

Choose a reason for hiding this comment

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

it's an equivalent to the reduce on the left - I've found it harder to read this reduce with concat so I've just refactored this to push+map

@Andarist Andarist merged commit df5ffce into main Dec 27, 2021
@Andarist Andarist deleted the andarist/fix-multiple-exit-calls branch December 27, 2021 16:14
This was referenced Dec 27, 2021
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.

None yet

2 participants