Skip to content

Commit a959781

Browse files
committed
fix(runtime-core): update devtool __vnode on patch, avoid memory leak during dev
close #11192
1 parent 3169c91 commit a959781

File tree

2 files changed

+10
-20
lines changed

2 files changed

+10
-20
lines changed

packages/runtime-core/src/hydration.ts

+3-12
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { warn } from './warning'
1717
import {
1818
PatchFlags,
1919
ShapeFlags,
20+
def,
2021
includeBooleanAttr,
2122
isBooleanAttr,
2223
isKnownHtmlAttr,
@@ -141,18 +142,8 @@ export function createHydrationFunctions(
141142
vnode.el = node
142143

143144
if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) {
144-
if (!('__vnode' in node)) {
145-
Object.defineProperty(node, '__vnode', {
146-
value: vnode,
147-
enumerable: false,
148-
})
149-
}
150-
if (!('__vueParentComponent' in node)) {
151-
Object.defineProperty(node, '__vueParentComponent', {
152-
value: parentComponent,
153-
enumerable: false,
154-
})
155-
}
145+
def(node, '__vnode', vnode, true)
146+
def(node, '__vueParentComponent', parentComponent, true)
156147
}
157148

158149
if (patchFlag === PatchFlags.BAIL) {

packages/runtime-core/src/renderer.ts

+7-8
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
NOOP,
3434
PatchFlags,
3535
ShapeFlags,
36+
def,
3637
getGlobalThis,
3738
invokeArrayFns,
3839
isArray,
@@ -696,15 +697,10 @@ function baseCreateRenderer(
696697
}
697698

698699
if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) {
699-
Object.defineProperty(el, '__vnode', {
700-
value: vnode,
701-
enumerable: false,
702-
})
703-
Object.defineProperty(el, '__vueParentComponent', {
704-
value: parentComponent,
705-
enumerable: false,
706-
})
700+
def(el, '__vnode', vnode, true)
701+
def(el, '__vueParentComponent', parentComponent, true)
707702
}
703+
708704
if (dirs) {
709705
invokeDirectiveHook(vnode, null, parentComponent, 'beforeMount')
710706
}
@@ -805,6 +801,9 @@ function baseCreateRenderer(
805801
optimized: boolean,
806802
) => {
807803
const el = (n2.el = n1.el!)
804+
if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) {
805+
el.__vnode = n2
806+
}
808807
let { patchFlag, dynamicChildren, dirs } = n2
809808
// #1426 take the old vnode's patch flag into account since user may clone a
810809
// compiler-generated vnode, which de-opts to FULL_PROPS

0 commit comments

Comments
 (0)