Skip to content

Commit c9f8829

Browse files
authored
Properly Detect Circular Structures Fixes #31, #28
Properly Detect Circular Structures. Idea derived from: https://stackoverflow.com/a/55545121/16201934
1 parent 740b46c commit c9f8829

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

packages/devtool-extenstion/extension/core/injectGlobalHook.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ function injectHelpers(target) {
5555
};
5656

5757
const parseData = (data) => {
58+
//For Detecting Circular Structures
59+
const seen = new WeakSet();
5860
const stringifyResolver = function (k, v) {
5961
if (typeof v === "function") {
6062
return "function () {}";
@@ -77,6 +79,13 @@ function injectHelpers(target) {
7779
if (isReactNode(k, v)) {
7880
return "<REACT NODE>";
7981
}
82+
//Detect Circular Structure
83+
if (typeof v === "object" && v !== null) {
84+
if (seen.has(v)) {
85+
return "Circular Structure";
86+
}
87+
seen.add(v);
88+
}
8089
return v;
8190
};
8291

0 commit comments

Comments
 (0)