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

Inspector and parent window freeze when attempting to serialize an HTML element #42

Open
mutewinter opened this issue Sep 25, 2024 · 1 comment

Comments

@mutewinter
Copy link

mutewinter commented Sep 25, 2024

Took me a while to track this one down and I believe it's related to:

statelyai/xstate#4645
statelyai/xstate#4985

I was able to patch @statelyai/inspect package at version 0.4.0 to fix this issue:

diff --git a/dist/index.js b/dist/index.js
index 844efec2f70099dd0a5bc807d191a9f54bef28c6..237e6ef3a9e0a832781e33e043b906b26c2aa839 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -111,6 +111,9 @@ function idleCallback(cb) {
 
 // src/createInspector.ts
 var import_safe_stable_stringify = __toESM(require("safe-stable-stringify"));
+var safe_stable_stringify = import_safe_stable_stringify.configure({
+  maximumDepth: 10
+})
 function getRoot(actorRef) {
   let marker = actorRef;
   do {
@@ -273,7 +276,7 @@ function convertXStateEvent(inspectionEvent) {
       return {
         type: "@xstate.snapshot",
         event: inspectionEvent.event,
-        snapshot: JSON.parse((0, import_safe_stable_stringify.default)(inspectionEvent.snapshot)),
+        snapshot: JSON.parse((0, safe_stable_stringify)(inspectionEvent.snapshot)),
         sessionId: inspectionEvent.actorRef.sessionId,
         _version: package_default.version,
         createdAt: Date.now().toString(),
@@ -323,7 +326,7 @@ function createBrowserInspector(options) {
     ...defaultInspectorOptions,
     url: "https://stately.ai/inspect",
     filter: () => true,
-    serialize: (inspectionEvent) => JSON.parse((0, import_fast_safe_stringify.default)(inspectionEvent)),
+    serialize: (inspectionEvent) => JSON.parse((0, import_fast_safe_stringify.default)(inspectionEvent, null, 2, { depthLimit: 10, edgesLimit: 10 })),
     autoStart: true,
     iframe: null,
     ...options,

I'm not sure if these max depth values are the best they could be, but this did resolve my issue.

@mutewinter mutewinter changed the title Inspector freezes when attempting to serialize an HTML element Inspector and parent window freeze when attempting to serialize an HTML element Sep 25, 2024
@davidkpiano
Copy link
Member

Please provide a CodeSandbox reproduction. You can use one of the templates here: https://github.com/statelyai/xstate?tab=readme-ov-file#templates

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

2 participants