Skip to content

Commit

Permalink
fix(kit): detect vue doubly-linked node to avoid circular references …
Browse files Browse the repository at this point in the history
…on encoding (#638)
  • Loading branch information
webfansplz authored Oct 22, 2024
1 parent 19b31e4 commit 7ce234c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/devtools-kit/src/shared/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ function isArray(_data: unknown, proto: string): _data is unknown[] {
return proto === '[object Array]'
}

// See https://github1s.com/vuejs/core/blob/HEAD/packages/reactivity/src/dep.ts#L32-L33
function isVueReactiveLinkNode(node) {
const constructorName = node.constructor.name
return (constructorName === 'Dep' && 'activeLink' in node) || (constructorName === 'Link' && 'dep' in node)
}

/**
* This function is used to serialize object with handling circular references.
*
Expand Down Expand Up @@ -41,6 +47,9 @@ function encode(data: unknown, replacer: Replacer | null, list: unknown[], seen:
const index = list.length
const proto = Object.prototype.toString.call(data)
if (isObject(data, proto)) {
if (isVueReactiveLinkNode(data)) {
return index
}
stored = {}
seen.set(data, index)
list.push(stored)
Expand Down

0 comments on commit 7ce234c

Please sign in to comment.