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

[@xstate/inspect] Handle circular references gracefully in inspector. #1699

Merged
merged 5 commits into from
Dec 12, 2020

Conversation

davidkpiano
Copy link
Member

This PR fixes stringifying circular reference in @xstate/inspect by using fast-safe-stringify when normal JSON.stringify(...) throws.

Currently, this will result in the string "[Circular]" in the inspect UI, which is much better than completely failing (previous behavior):

CleanShot 2020-12-06 at 17 52 45@2x

Fixes #1497

@changeset-bot
Copy link

changeset-bot bot commented Dec 6, 2020

⚠️ No Changeset found

Latest commit: d980fc8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

packages/xstate-inspect/test/inspect.test.ts Outdated Show resolved Hide resolved
const devTools = createDevTools();

devTools.onRegister(() => {
done();
Copy link
Member

Choose a reason for hiding this comment

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

q: is this crucial for this test? or could we just stick to the "not throw" expectation on the end? I mean - onRegister gets called synchronously as far as i can see so this done() here in the middle of a test is slightly distracting (if only it can be avoided, i might miss something)

Copy link
Member Author

Choose a reason for hiding this comment

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

In the future, register/onRegister may be async, and if that happens, this test will fail.

packages/xstate-inspect/src/index.ts Show resolved Hide resolved
packages/xstate-inspect/src/index.ts Show resolved Hide resolved
packages/xstate-inspect/src/index.ts Outdated Show resolved Hide resolved
packages/xstate-inspect/src/index.ts Show resolved Hide resolved
davidkpiano and others added 2 commits December 8, 2020 08:45
Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
@davidkpiano davidkpiano merged commit 7aad3c6 into master Dec 12, 2020
@davidkpiano davidkpiano deleted the davidkpiano/1497 branch December 12, 2020 21:51
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.

The visualizer breaks on JSON.stringify calls when there are circular references in machine definition
2 participants