]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-core): stricter compat root mount check
authorEvan You <yyx990803@gmail.com>
Fri, 28 May 2021 00:47:46 +0000 (20:47 -0400)
committerEvan You <yyx990803@gmail.com>
Fri, 28 May 2021 00:47:46 +0000 (20:47 -0400)
packages/runtime-core/__tests__/rendererComponent.spec.ts
packages/runtime-core/src/compat/global.ts
packages/runtime-core/src/renderer.ts
packages/runtime-core/src/vnode.ts

index fc004045fd9587743d7a706f475f3f12c4a22c4f..4d20ca80b60b2cea81e075dfcb60d58e9a7f3611 100644 (file)
@@ -298,12 +298,10 @@ describe('renderer: component', () => {
   })
 
   test('the component VNode should be cloned when reusing it', () => {
-    const Child = {
-      setup(props: any, { slots }: SetupContext) {
-        return () => {
-          const c = slots.default!()
-          return [c, c, c]
-        }
+    const App = {
+      render() {
+        const c = [h(Comp)]
+        return [c, c, c]
       }
     }
 
@@ -315,14 +313,6 @@ describe('renderer: component', () => {
       }
     }
 
-    const App = {
-      setup() {
-        return () => {
-          return h(Child, () => [h(Comp)])
-        }
-      }
-    }
-
     const root = nodeOps.createElement('div')
     render(h(App), root)
     expect(serializeInner(root)).toBe(`<h1></h1><h1></h1><h1></h1>`)
index 8b100254b1995fa87b5a9d6433b467f00cc9700d..3d518f4424eda70838422afc7a6c9494abe597b0 100644 (file)
@@ -472,6 +472,7 @@ function installCompatMount(
     }
     setupComponent(instance)
     vnode.component = instance
+    vnode.isCompatRoot = true
 
     // $mount & $destroy
     // these are defined on ctx and picked up by the $mount/$destroy
index 1da8cd09720648ab5cc93fc628cdf49a7ba1b7eb..36291a24f4774ed651fd0fb867191c4d09035a68 100644 (file)
@@ -1301,7 +1301,8 @@ function baseCreateRenderer(
   ) => {
     // 2.x compat may pre-creaate the component instance before actually
     // mounting
-    const compatMountInstance = __COMPAT__ && initialVNode.component
+    const compatMountInstance =
+      __COMPAT__ && initialVNode.isCompatRoot && initialVNode.component
     const instance: ComponentInternalInstance =
       compatMountInstance ||
       (initialVNode.component = createComponentInstance(
index da99f2ece3178d8da3da27f02da007f881d1c658..ec5a8f5dc61a17a487cf150a35aa19d6a1eeaa39 100644 (file)
@@ -136,6 +136,11 @@ export interface VNode<
    */
   [ReactiveFlags.SKIP]: true
 
+  /**
+   * @internal __COMPAT__ only
+   */
+  isCompatRoot?: true
+
   type: VNodeTypes
   props: (VNodeProps & ExtraProps) | null
   key: string | number | null