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 issues around reentrancy during external transitions #3677

Merged
merged 4 commits into from
Nov 16, 2022

Conversation

Andarist
Copy link
Member

@Andarist Andarist commented Nov 14, 2022

We didn't have an explicit issue open about those fixed issues. Those are things that I've spotted when investigating some issue reports and when reviewing some other PR.

The issue with the targeted ancestor not being exited correctly when it was already being entered during reentering transition has been mentioned in the second point here:
#3613 (comment)

@changeset-bot
Copy link

changeset-bot bot commented Nov 14, 2022

🦋 Changeset detected

Latest commit: c99f608

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 Nov 14, 2022

👇 Click on the image for a new way to code review
  • Make big changes easier — review code in small groups of related files

  • Know where to start — see the whole change at a glance

  • Take a code tour — explore the change with an interactive tour

  • Make comments and review — all fully sync’ed with github

    Try it now!

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map Legend

@codesandbox-ci
Copy link

codesandbox-ci bot commented Nov 14, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit c99f608:

Sandbox Source
XState Example Template Configuration
XState React Template Configuration

@Andarist Andarist force-pushed the andarist/test-utils-entry-exit-tracking branch from 981efb7 to 4eb8ea6 Compare November 14, 2022 13:00
@@ -725,7 +727,8 @@ describe('entry/exit actions', () => {
'exit: a.a1',
'exit: a',
'enter: a',
'enter: a.a1'
'enter: a.a1',
'enter: a.a1.a11'
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 has regressed in #3424

Base automatically changed from andarist/test-utils-entry-exit-tracking to main November 14, 2022 13:56
]);
});

it('should reenter leaf state during its self-transition', () => {
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 test and the other ones added below were already working. I was trying to "break" the existing implementation for those cases but they seem to work fine. They might overlap with some existing tests but I've figured out that it's better to have more than fewer tests so I've committed them 😜

) {
transition.entrySet.push(sn);
entrySet.add(sn);
}
}
for (const sn of prevConfig) {
Copy link
Member Author

Choose a reason for hiding this comment

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

I think that the logic in this for-of loop is fragile but I couldn't make it break right now. Perhaps it's because nodes in the prevConfig are already sorted in a way that allows this for-of loop to do its job.

@Andarist Andarist marked this pull request as ready for review November 14, 2022 16:30
@@ -647,6 +648,7 @@ describe('entry/exit actions', () => {
expect(flushTracked()).toEqual([
'exit: A.A2.A2_child',
'exit: A.A2',
'exit: A',
Copy link
Member

Choose a reason for hiding this comment

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

So strange; I wonder why these were expected to be omitted (not exited) originally. What was our stance on whether to exit the root node or not?

Copy link
Member Author

Choose a reason for hiding this comment

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

So strange; I wonder why these were expected to be omitted (not exited) originally.

It wasn't expected. When working on #3424 I've focused only on one side of the reentrancy (re-entering) but I've missed that I didn't actually fix the other half of the story - that the reentered state has to exit first.

What was our stance on whether to exit the root node or not?

In v4 we can exit the root state, in v5 this should become impossible (or at least that's what we've decided in the past months).

Copy link
Member

@davidkpiano davidkpiano left a comment

Choose a reason for hiding this comment

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

Code LGTM if we're okay with exiting/entering the root node (only concern)

@Andarist Andarist merged commit a2ecf97 into main Nov 16, 2022
@Andarist Andarist deleted the andarist/fix-reentrancy branch November 16, 2022 15:59
@github-actions github-actions bot mentioned this pull request Nov 16, 2022
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