2
0
Эх сурвалжийг харах

fix(custom-element): avoid retaining custom element hooks on shared definitions

daiwei 1 долоо хоног өмнө
parent
commit
cb1f10b5e6

+ 9 - 11
packages/runtime-vapor/src/apiDefineCustomElement.ts

@@ -1,11 +1,6 @@
 import { shallowReactive } from '@vue/reactivity'
 import { extend, isPlainObject } from '@vue/shared'
-import {
-  createComponent,
-  createVaporApp,
-  createVaporSSRApp,
-  defineVaporComponent,
-} from '.'
+import { createVaporApp, createVaporSSRApp, defineVaporComponent } from '.'
 import {
   type ComponentObjectPropsOptions,
   type CreateAppFunction,
@@ -17,10 +12,11 @@ import {
   VueElementBase,
   warn,
 } from '@vue/runtime-dom'
-import type {
-  VaporComponent,
-  VaporComponentInstance,
-  VaporComponentOptions,
+import {
+  type VaporComponent,
+  type VaporComponentInstance,
+  type VaporComponentOptions,
+  createComponent,
 } from './component'
 import type { Block } from './block'
 import { withHydration } from './dom/hydration'
@@ -335,7 +331,7 @@ export class VaporElement extends VueElementBase<
   }
 
   private _createComponent() {
-    this._def.ce = instance => {
+    const ce = (instance: VaporComponentInstance) => {
       this._app!._ceComponent = this._instance = instance
       // For shadowRoot: false, _renderSlots is called synchronously after mount
       // in _mount() to ensure correct lifecycle order
@@ -353,6 +349,8 @@ export class VaporElement extends VueElementBase<
       undefined,
       undefined,
       this._app!._context,
+      false,
+      ce,
     )
   }
 }

+ 5 - 6
packages/runtime-vapor/src/component.ts

@@ -215,10 +215,6 @@ export interface VaporComponentOptions<
   name?: string
   vapor?: boolean
   components?: Record<string, VaporComponent>
-  /**
-   * @internal custom element interception hook
-   */
-  ce?: (instance: VaporComponentInstance) => void
 }
 
 interface SharedInternalOptions {
@@ -257,6 +253,7 @@ export function createComponent(
     currentInstance.appContext) ||
     emptyContext,
   managedMount = false,
+  ce?: (instance: VaporComponentInstance) => void,
 ): VaporComponentInstance {
   // A component created while rendering a v-once slot should receive frozen
   // parent inputs, but its own render effects should still be live.
@@ -391,6 +388,7 @@ export function createComponent(
       rawSlots,
       appContext,
       once,
+      ce,
     )
 
     // handle currentKeepAliveCtx for component boundary isolation
@@ -771,6 +769,7 @@ export class VaporComponentInstance<
     rawSlots?: LooseRawSlots | null,
     appContext?: GenericAppContext,
     once?: boolean,
+    ce?: (instance: VaporComponentInstance) => void,
   ) {
     this.vapor = true
     this.uid = nextUid()
@@ -848,8 +847,8 @@ export class VaporComponentInstance<
     this.scopeId = getCurrentScopeId()
 
     // apply custom element special handling
-    if (comp.ce) {
-      comp.ce(this)
+    if (ce) {
+      ce(this)
     }
 
     if (__DEV__) {