Skip to content

Commit

Permalink
fix(runtime-core): update devtool __vnode on patch, avoid memory leak…
Browse files Browse the repository at this point in the history
… during dev

close #11192
  • Loading branch information
yyx990803 committed Jun 22, 2024
1 parent 3169c91 commit a959781
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
15 changes: 3 additions & 12 deletions packages/runtime-core/src/hydration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { warn } from './warning'
import {
PatchFlags,
ShapeFlags,
def,
includeBooleanAttr,
isBooleanAttr,
isKnownHtmlAttr,
Expand Down Expand Up @@ -141,18 +142,8 @@ export function createHydrationFunctions(
vnode.el = node

if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) {
if (!('__vnode' in node)) {
Object.defineProperty(node, '__vnode', {
value: vnode,
enumerable: false,
})
}
if (!('__vueParentComponent' in node)) {
Object.defineProperty(node, '__vueParentComponent', {
value: parentComponent,
enumerable: false,
})
}
def(node, '__vnode', vnode, true)
def(node, '__vueParentComponent', parentComponent, true)
}

if (patchFlag === PatchFlags.BAIL) {
Expand Down
15 changes: 7 additions & 8 deletions packages/runtime-core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
NOOP,
PatchFlags,
ShapeFlags,
def,
getGlobalThis,
invokeArrayFns,
isArray,
Expand Down Expand Up @@ -696,15 +697,10 @@ function baseCreateRenderer(
}

if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) {
Object.defineProperty(el, '__vnode', {
value: vnode,
enumerable: false,
})
Object.defineProperty(el, '__vueParentComponent', {
value: parentComponent,
enumerable: false,
})
def(el, '__vnode', vnode, true)
def(el, '__vueParentComponent', parentComponent, true)
}

if (dirs) {
invokeDirectiveHook(vnode, null, parentComponent, 'beforeMount')
}
Expand Down Expand Up @@ -805,6 +801,9 @@ function baseCreateRenderer(
optimized: boolean,
) => {
const el = (n2.el = n1.el!)
if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) {
el.__vnode = n2
}
let { patchFlag, dynamicChildren, dirs } = n2
// #1426 take the old vnode's patch flag into account since user may clone a
// compiler-generated vnode, which de-opts to FULL_PROPS
Expand Down

0 comments on commit a959781

Please sign in to comment.