Просмотр исходного кода

refactor(runtime-core): replace VueElement import with ComponentCustomElementInterface (#14348)

edison 3 месяцев назад
Родитель
Сommit
e1ccd9fde8

+ 8 - 0
packages/runtime-core/src/component.ts

@@ -1257,6 +1257,10 @@ export function isClassComponent(value: unknown): value is ClassComponent {
 }
 
 export interface ComponentCustomElementInterface {
+  /**
+   * @internal
+   */
+  _isVueCE: boolean
   /**
    * @internal
    */
@@ -1286,4 +1290,8 @@ export interface ComponentCustomElementInterface {
    * @internal attached by the nested Teleport when shadowRoot is false.
    */
   _teleportTargets?: Set<RendererElement>
+  /**
+   * @internal check if shadow root is enabled
+   */
+  _hasShadowRoot(): boolean
 }

+ 6 - 9
packages/runtime-core/src/renderer.ts

@@ -86,7 +86,7 @@ import { isAsyncWrapper } from './apiAsyncComponent'
 import { isCompatEnabled } from './compat/compatConfig'
 import { DeprecationTypes } from './compat/compatConfig'
 import { type TransitionHooks, leaveCbKey } from './components/BaseTransition'
-import type { VueElement } from '@vue/runtime-dom'
+import type { ComponentCustomElementInterface } from './component'
 
 export interface Renderer<HostElement = RendererElement> {
   render: RootRenderFunction<HostElement>
@@ -641,9 +641,10 @@ function baseCreateRenderer(
         optimized,
       )
     } else {
-      const customElement = !!(n1.el && (n1.el as VueElement)._isVueCE)
-        ? (n1.el as VueElement)
-        : null
+      const customElement =
+        n1.el && (n1.el as ComponentCustomElementInterface)._isVueCE
+          ? (n1.el as ComponentCustomElementInterface)
+          : null
       try {
         if (customElement) {
           customElement._beginPatch()
@@ -1385,11 +1386,7 @@ function baseCreateRenderer(
           }
         } else {
           // custom element style injection
-          if (
-            root.ce &&
-            // @ts-expect-error _def is private
-            (root.ce as VueElement)._def.shadowRoot !== false
-          ) {
+          if (root.ce && root.ce._hasShadowRoot()) {
             root.ce._injectChildStyle(type)
           }
 

+ 7 - 0
packages/runtime-dom/src/apiCustomElement.ts

@@ -725,6 +725,13 @@ export class VueElement
     }
   }
 
+  /**
+   * @internal
+   */
+  _hasShadowRoot(): boolean {
+    return this._def.shadowRoot !== false
+  }
+
   /**
    * @internal
    */