From: Evan You Date: Tue, 27 Sep 2022 08:20:43 +0000 (+0800) Subject: fix(runtime-core): avoid hoisted vnodes retaining detached DOM nodes X-Git-Tag: v3.2.40~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fc5bdb36ed429d6c3c956f373206ce75467adaf3;p=thirdparty%2Fvuejs%2Fcore.git fix(runtime-core): avoid hoisted vnodes retaining detached DOM nodes fix #6591 --- diff --git a/packages/compiler-core/__tests__/transforms/hoistStatic.spec.ts b/packages/compiler-core/__tests__/transforms/hoistStatic.spec.ts index 2c4421aeb3..eec5a76d36 100644 --- a/packages/compiler-core/__tests__/transforms/hoistStatic.spec.ts +++ b/packages/compiler-core/__tests__/transforms/hoistStatic.spec.ts @@ -13,7 +13,6 @@ import { import { FRAGMENT, RENDER_LIST, - CREATE_TEXT, NORMALIZE_CLASS } from '../../src/runtimeHelpers' import { transformElement } from '../../src/transforms/transformElement' @@ -378,36 +377,6 @@ describe('compiler: hoistStatic transform', () => { expect(generate(root).code).toMatchSnapshot() }) - test('hoist static text node between elements', () => { - const root = transformWithHoist(`
static
static
`) - expect(root.hoists).toMatchObject([ - { - callee: CREATE_TEXT, - arguments: [ - { - type: NodeTypes.TEXT, - content: `static` - } - ] - }, - { - type: NodeTypes.VNODE_CALL, - tag: `"div"` - }, - { - type: NodeTypes.JS_ARRAY_EXPRESSION, - elements: [ - { - type: NodeTypes.TEXT_CALL - }, - { - type: NodeTypes.ELEMENT - } - ] - } - ]) - }) - describe('prefixIdentifiers', () => { test('hoist nested static tree with static interpolation', () => { const root = transformWithHoist( @@ -618,7 +587,9 @@ describe('compiler: hoistStatic transform', () => { }) test('should NOT hoist SVG with directives', () => { - const root = transformWithHoist(`
`) + const root = transformWithHoist( + `
` + ) expect(root.hoists.length).toBe(2) expect(generate(root).code).toMatchSnapshot() }) diff --git a/packages/compiler-core/src/transforms/hoistStatic.ts b/packages/compiler-core/src/transforms/hoistStatic.ts index 848052581e..b2b7f871c0 100644 --- a/packages/compiler-core/src/transforms/hoistStatic.ts +++ b/packages/compiler-core/src/transforms/hoistStatic.ts @@ -97,12 +97,6 @@ function walk( } } } - } else if ( - child.type === NodeTypes.TEXT_CALL && - getConstantType(child.content, context) >= ConstantTypes.CAN_HOIST - ) { - child.codegenNode = context.hoist(child.codegenNode) - hoistedCount++ } // walk further diff --git a/packages/runtime-core/src/vnode.ts b/packages/runtime-core/src/vnode.ts index 6a43d97d7d..b731dc0b51 100644 --- a/packages/runtime-core/src/vnode.ts +++ b/packages/runtime-core/src/vnode.ts @@ -737,7 +737,10 @@ export function normalizeVNode(child: VNodeChild): VNode { // optimized normalization for template-compiled render fns export function cloneIfMounted(child: VNode): VNode { - return child.el === null || child.memo ? child : cloneVNode(child) + return (child.el === null && child.patchFlag !== PatchFlags.HOISTED) || + child.memo + ? child + : cloneVNode(child) } export function normalizeChildren(vnode: VNode, children: unknown) {