Explorar el Código

wip(vapor): support vapor component as root in vdom app

Evan You hace 1 año
padre
commit
a770a83de6
Se han modificado 1 ficheros con 7 adiciones y 5 borrados
  1. 7 5
      packages/runtime-core/src/renderer.ts

+ 7 - 5
packages/runtime-core/src/renderer.ts

@@ -1160,14 +1160,14 @@ function baseCreateRenderer(
 
     if ((n2.type as ConcreteComponent).__vapor) {
       if (n1 == null) {
-        getVaporInterface(parentComponent).mount(
+        getVaporInterface(parentComponent, n2).mount(
           n2,
           container,
           anchor,
           parentComponent,
         )
       } else {
-        getVaporInterface(parentComponent).update(
+        getVaporInterface(parentComponent, n2).update(
           n1,
           n2,
           shouldUpdateComponent(n1, n2, optimized),
@@ -2055,7 +2055,7 @@ function baseCreateRenderer(
     const { el, type, transition, children, shapeFlag } = vnode
     if (shapeFlag & ShapeFlags.COMPONENT) {
       if ((type as ConcreteComponent).__vapor) {
-        getVaporInterface(parentComponent).move(vnode, container, anchor)
+        getVaporInterface(parentComponent, vnode).move(vnode, container, anchor)
       } else {
         move(
           vnode.component!.subTree,
@@ -2185,7 +2185,7 @@ function baseCreateRenderer(
 
     if (shapeFlag & ShapeFlags.COMPONENT) {
       if ((type as ConcreteComponent).__vapor) {
-        getVaporInterface(parentComponent).unmount(vnode, doRemove)
+        getVaporInterface(parentComponent, vnode).unmount(vnode, doRemove)
       } else {
         unmountComponent(vnode.component!, parentSuspense, doRemove)
       }
@@ -2620,8 +2620,10 @@ export function invalidateMount(hooks: LifecycleHook | undefined): void {
 
 function getVaporInterface(
   instance: ComponentInternalInstance | null,
+  vnode: VNode,
 ): VaporInteropInterface {
-  const res = instance!.appContext.vapor
+  const ctx = instance ? instance.appContext : vnode.appContext
+  const res = ctx && ctx.vapor
   if (__DEV__ && !res) {
     warn(
       `Vapor component found in vdom tree but vapor-in-vdom interop was not installed. ` +