Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7ce234c

Browse files
authored
fix(kit): detect vue doubly-linked node to avoid circular references on encoding (#638)
1 parent 19b31e4 commit 7ce234c

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

packages/devtools-kit/src/shared/transfer.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ function isArray(_data: unknown, proto: string): _data is unknown[] {
1111
return proto === '[object Array]'
1212
}
1313

14+
// See https://github1s.com/vuejs/core/blob/HEAD/packages/reactivity/src/dep.ts#L32-L33
15+
function isVueReactiveLinkNode(node) {
16+
const constructorName = node.constructor.name
17+
return (constructorName === 'Dep' && 'activeLink' in node) || (constructorName === 'Link' && 'dep' in node)
18+
}
19+
1420
/**
1521
* This function is used to serialize object with handling circular references.
1622
*
@@ -41,6 +47,9 @@ function encode(data: unknown, replacer: Replacer | null, list: unknown[], seen:
4147
const index = list.length
4248
const proto = Object.prototype.toString.call(data)
4349
if (isObject(data, proto)) {
50+
if (isVueReactiveLinkNode(data)) {
51+
return index
52+
}
4453
stored = {}
4554
seen.set(data, index)
4655
list.push(stored)

0 commit comments

Comments
 (0)