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 initial state of invoked machines being read without custom data #1285

Merged
merged 3 commits into from
Jul 8, 2020

Conversation

Andarist
Copy link
Member

@Andarist Andarist commented Jul 5, 2020

fixes #1277

This has a caveat though - in a normal situation a service creator is called here:
https://github.com/davidkpiano/xstate/blob/8226700aab94031f66133c6518430786aab4780c/packages/core/src/interpreter.ts#L871-L877
and it is called with different values - _event (nor context) is not guaranteed to be the same between those 2 points in time. I don't feel this is fixable easily in v4 though.

@Andarist Andarist requested a review from davidkpiano July 5, 2020 08:11
@changeset-bot
Copy link

changeset-bot bot commented Jul 5, 2020

🦋 Changeset is good to go

Latest commit: 27bfd3a

We got this.

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

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jul 5, 2020

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 27bfd3a:

Sandbox Source
XState Example Template Configuration
XState React Template Configuration
boring-kepler-uv1or Issue #1277

@@ -629,4 +629,45 @@ describe('transient states (eventless transitions)', () => {

service.send('ADD');
});

it("shouldn't crash when invoking a machine with initial transient transition depending on custom data", () => {
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 is not the best test as @davidkpiano's proposed workaround here is valid (to some extent). One should not rely on undefined context - if TContext parameter is configured then .context should satisfy that constraint at all times and thus expressions (like guards) should not fail due to some properties being missed.

However, I don't know what other observable behavior to test at XState layer. The other added test (@xstate/react) is much better: https://github.com/davidkpiano/xstate/pull/1285/files#diff-326fee0dc0480200270263670a5d51bfR608

Copy link
Member Author

Choose a reason for hiding this comment

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

@davidkpiano do you think this test here is worth keeping?

Copy link
Member

Choose a reason for hiding this comment

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

I think so, yes.

@Andarist Andarist merged commit 0c35217 into master Jul 8, 2020
@Andarist Andarist deleted the fix/invoked-initial-state branch July 8, 2020 15:14
@github-actions github-actions bot mentioned this pull request Jul 8, 2020
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.

Eventless/transient transitions in invoked machines are evaluated without context from parent
2 participants