Skip to content

Commit fc5bdb3

Browse files
committed
fix(runtime-core): avoid hoisted vnodes retaining detached DOM nodes
fix #6591
1 parent ab8bfac commit fc5bdb3

File tree

3 files changed

+7
-39
lines changed

3 files changed

+7
-39
lines changed

packages/compiler-core/__tests__/transforms/hoistStatic.spec.ts

+3-32
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
import {
1414
FRAGMENT,
1515
RENDER_LIST,
16-
CREATE_TEXT,
1716
NORMALIZE_CLASS
1817
} from '../../src/runtimeHelpers'
1918
import { transformElement } from '../../src/transforms/transformElement'
@@ -378,36 +377,6 @@ describe('compiler: hoistStatic transform', () => {
378377
expect(generate(root).code).toMatchSnapshot()
379378
})
380379

381-
test('hoist static text node between elements', () => {
382-
const root = transformWithHoist(`<div>static<div>static</div></div>`)
383-
expect(root.hoists).toMatchObject([
384-
{
385-
callee: CREATE_TEXT,
386-
arguments: [
387-
{
388-
type: NodeTypes.TEXT,
389-
content: `static`
390-
}
391-
]
392-
},
393-
{
394-
type: NodeTypes.VNODE_CALL,
395-
tag: `"div"`
396-
},
397-
{
398-
type: NodeTypes.JS_ARRAY_EXPRESSION,
399-
elements: [
400-
{
401-
type: NodeTypes.TEXT_CALL
402-
},
403-
{
404-
type: NodeTypes.ELEMENT
405-
}
406-
]
407-
}
408-
])
409-
})
410-
411380
describe('prefixIdentifiers', () => {
412381
test('hoist nested static tree with static interpolation', () => {
413382
const root = transformWithHoist(
@@ -618,7 +587,9 @@ describe('compiler: hoistStatic transform', () => {
618587
})
619588

620589
test('should NOT hoist SVG with directives', () => {
621-
const root = transformWithHoist(`<div><svg v-foo><path d="M2,3H5.5L12"/></svg></div>`)
590+
const root = transformWithHoist(
591+
`<div><svg v-foo><path d="M2,3H5.5L12"/></svg></div>`
592+
)
622593
expect(root.hoists.length).toBe(2)
623594
expect(generate(root).code).toMatchSnapshot()
624595
})

packages/compiler-core/src/transforms/hoistStatic.ts

-6
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,6 @@ function walk(
9797
}
9898
}
9999
}
100-
} else if (
101-
child.type === NodeTypes.TEXT_CALL &&
102-
getConstantType(child.content, context) >= ConstantTypes.CAN_HOIST
103-
) {
104-
child.codegenNode = context.hoist(child.codegenNode)
105-
hoistedCount++
106100
}
107101

108102
// walk further

packages/runtime-core/src/vnode.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,10 @@ export function normalizeVNode(child: VNodeChild): VNode {
737737

738738
// optimized normalization for template-compiled render fns
739739
export function cloneIfMounted(child: VNode): VNode {
740-
return child.el === null || child.memo ? child : cloneVNode(child)
740+
return (child.el === null && child.patchFlag !== PatchFlags.HOISTED) ||
741+
child.memo
742+
? child
743+
: cloneVNode(child)
741744
}
742745

743746
export function normalizeChildren(vnode: VNode, children: unknown) {

0 commit comments

Comments
 (0)