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

Cyclical always transitions result in "Maximum callstack exceeded" error #22

Closed
Silverwolf90 opened this issue Oct 26, 2021 · 6 comments

Comments

@Silverwolf90
Copy link

Silverwolf90 commented Oct 26, 2021

This codesandbox includes a 2 state example. I've also experienced the same behavior with 3 states so assume it's related any cycle from always transitions.

Additionally, the inspector doesn't render anything when this cycle is present. But after commenting an always transition in the cycle, it renders correctly.

This renders correctly in the visualizer (independent of the vscode extension) with no issues.

@wKovacs64
Copy link

Someone in Discord pointed out that inlining the guards makes the error go away. Unfortunately, doing that prevents you from using the visual editor.

@Andarist
Copy link
Member

Huh, inlining a guard vs referencing a guard should definitely not result in such a behavior difference. This is definitely a bug - and most likely in XState itself

@wKovacs64
Copy link

Huh, inlining a guard vs referencing a guard should definitely not result in such a behavior difference. This is definitely a bug - and most likely in XState itself

To be clear, the machine executes properly at runtime regardless of where the guard is defined. It seems the VSCode extension just can't handle cyclic always transitions and for some reason inlining the guard prevents the maximum callstack exceeded error (but inlining the guard might just be causing the extension to fail/abort parsing the machine before the error can happen?).

@mattpocock
Copy link
Contributor

Found a fix for this. XState was erroring too soon when you didn't provide a guard that was checked as part of an initial state. So we extract a bunch of 'guards to mock' from the machine definition.

By default, we were setting these guards as () => true. But we don't need to. Setting them as () => false works.

@mattpocock mattpocock reopened this Feb 2, 2022
@mattpocock
Copy link
Contributor

mattpocock commented Feb 2, 2022

(reopening pending @wKovacs64 feedback on a version distributed privately)

@wKovacs64
Copy link

For those following along at home, it worked!

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

No branches or pull requests

4 participants