-
-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(kit): avoid circular vue instance ref when encoding state (#429)
- Loading branch information
1 parent
c0df970
commit 7c32103
Showing
6 changed files
with
146 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
packages/devtools-kit/src/shared/__test__/__snapshots__/transfer.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`encode 1`] = `" [{"_":1,"__isVue":23,"a":24,"b":25},{"ctx":2,"vnode":4,"type":14,"appContext":16,"setupState":18,"attrs":19,"provides":20,"injects":21,"refs":22},{"props":3},{},[5],{"_custom":6},{"type":7,"id":8,"displayText":9,"tooltipText":10,"value":11,"fields":12},"component","__vue_devtool_undefined__","Anonymous Component","Component instance","__vue_devtool_undefined__",{"abstract":13},true,{"props":15},[],{"mixins":17},[],{},{},{},{},{},true,1,{"state":26},[27,31],{"type":28,"key":29,"value":30},"provided","$currentInstance","[[CircularRef]] <Anonymous Component>",{"type":32,"key":33,"value":34},"provided","$currentInstance2","[[CircularRef]] <Anonymous Component>"]"`; |
45 changes: 45 additions & 0 deletions
45
packages/devtools-kit/src/shared/__test__/transfer.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { stringifyReplacer } from '../../core/component/state/replacer' | ||
import { stringifyStrictCircularAutoChunks } from '../transfer' | ||
|
||
it('encode', () => { | ||
const vueInstanceLike = { | ||
_: { | ||
ctx: { | ||
props: {}, | ||
}, | ||
vnode: [] as any[], | ||
type: { | ||
props: [], | ||
}, | ||
appContext: { | ||
mixins: [], | ||
}, | ||
setupState: {}, | ||
attrs: {}, | ||
provides: {}, | ||
injects: {}, | ||
refs: {}, | ||
}, | ||
__isVue: true, | ||
a: 1, | ||
b: { | ||
state: [] as any[], | ||
}, | ||
} | ||
|
||
vueInstanceLike.b.state.push({ | ||
type: 'provided', | ||
key: '$currentInstance', | ||
value: vueInstanceLike, | ||
}) | ||
|
||
vueInstanceLike.b.state.push({ | ||
type: 'provided', | ||
key: '$currentInstance2', | ||
value: vueInstanceLike, | ||
}) | ||
|
||
vueInstanceLike._.vnode.push(vueInstanceLike) | ||
|
||
expect(stringifyStrictCircularAutoChunks(vueInstanceLike, stringifyReplacer)).toMatchSnapshot() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<script lang="ts"> | ||
const getCircularState = () => { | ||
const obj = { | ||
a: 1, | ||
b: 2, | ||
} | ||
// @ts-expect-error - Circular reference | ||
obj.c = obj | ||
return obj | ||
} | ||
export default { | ||
provide() { | ||
return { | ||
$currentInstance: this, | ||
$currentInstance2: this, | ||
} | ||
}, | ||
data() { | ||
return { | ||
circularState: getCircularState(), | ||
} | ||
}, | ||
} | ||
</script> | ||
|
||
<template> | ||
<div /> | ||
</template> |