]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-vapor): component self-reference
author三咲智子 Kevin Deng <sxzz@sxzz.moe>
Wed, 13 Nov 2024 02:57:22 +0000 (10:57 +0800)
committer三咲智子 Kevin Deng <sxzz@sxzz.moe>
Wed, 13 Nov 2024 03:00:07 +0000 (11:00 +0800)
packages/runtime-vapor/__tests__/helpers/resolveAssets.spec.ts
packages/runtime-vapor/src/component.ts
packages/runtime-vapor/src/helpers/resolveAssets.ts

index 366edc83dcee307a09473520be6de1e88925ba5a..fb4a4aa04d6a7bf115c9cc4358620d7443be7af8 100644 (file)
@@ -54,28 +54,7 @@ describe('resolveAssets', () => {
     expect(directive3!).toBe(BarBaz)
     expect(directive4!).toBe(BarBaz)
   })
-  test('maybeSelfReference', async () => {
-    let component1: Component | string
-    let component2: Component | string
-    let component3: Component | string
-    const Foo = () => []
-    const Root = define({
-      name: 'Root',
-      render() {
-        component1 = resolveComponent('Root', true)
-        component2 = resolveComponent('Foo', true)
-        component3 = resolveComponent('Bar', true)
-        return []
-      },
-    })
-    const app = createVaporApp(Root.component)
-    app.component('Foo', Foo)
-    const root = document.createElement('div')
-    app.mount(root)
-    expect(component1!).toMatchObject(Root.component) // explicit self name reference
-    expect(component2!).toBe(Foo) // successful resolve take higher priority
-    expect(component3!).toMatchObject(Root.component) // fallback when resolve fails
-  })
+
   describe('warning', () => {
     test('used outside render() or setup()', () => {
       resolveComponent('foo')
index 0c9901da0df62286a6c8fb40b523fec5192c4bcd..ca0cb7fa04f7e6a54b5f2de2d73b7a1fec797544 100644 (file)
@@ -425,11 +425,10 @@ function getSlotsProxy(instance: ComponentInternalInstance): StaticSlots {
 
 export function getComponentName(
   Component: Component,
-  includeInferred = true,
 ): string | false | undefined {
   return isFunction(Component)
     ? Component.displayName || Component.name
-    : Component.name || (includeInferred && Component.__name)
+    : Component.name || Component.__name
 }
 
 export function formatComponentName(
index 493b11a63d55a8e724c084963679b20d2fc93f91..06bd31f57f5f6796d3b405f2432220d51ed13445 100644 (file)
@@ -8,11 +8,8 @@ export const DIRECTIVES = 'directives'
 
 export type AssetTypes = typeof COMPONENTS | typeof DIRECTIVES
 
-export function resolveComponent(
-  name: string,
-  maybeSelfReference?: boolean,
-): string | Component {
-  return resolveAsset(COMPONENTS, name, true, maybeSelfReference) || name
+export function resolveComponent(name: string): string | Component {
+  return resolveAsset(COMPONENTS, name, true) || name
 }
 
 export function resolveDirective(name: string): Directive | undefined {
@@ -27,7 +24,6 @@ function resolveAsset(
   type: typeof COMPONENTS,
   name: string,
   warnMissing?: boolean,
-  maybeSelfReference?: boolean,
 ): Component | undefined
 // overload 2: directives
 function resolveAsset(
@@ -35,22 +31,14 @@ function resolveAsset(
   name: string,
 ): Directive | undefined
 // implementation
-function resolveAsset(
-  type: AssetTypes,
-  name: string,
-  warnMissing = true,
-  maybeSelfReference = false,
-) {
+function resolveAsset(type: AssetTypes, name: string, warnMissing = true) {
   const instance = currentInstance
   if (instance) {
     const Component = instance.type
 
     // explicit self name has highest priority
     if (type === COMPONENTS) {
-      const selfName = getComponentName(
-        Component,
-        false /* do not include inferred name to avoid breaking existing code */,
-      )
+      const selfName = getComponentName(Component)
       if (
         selfName &&
         (selfName === name ||
@@ -65,11 +53,6 @@ function resolveAsset(
       // global registration
       resolve(instance.appContext[type], name)
 
-    if (!res && maybeSelfReference) {
-      // fallback to implicit self-reference
-      return Component
-    }
-
     if (__DEV__ && warnMissing && !res) {
       const extra =
         type === COMPONENTS