Skip to content

Commit fab9917

Browse files
committed
fix(runtime-vapor): component self-reference
1 parent 114d501 commit fab9917

File tree

3 files changed

+6
-45
lines changed

3 files changed

+6
-45
lines changed

packages/runtime-vapor/__tests__/helpers/resolveAssets.spec.ts

+1-22
Original file line numberDiff line numberDiff line change
@@ -54,28 +54,7 @@ describe('resolveAssets', () => {
5454
expect(directive3!).toBe(BarBaz)
5555
expect(directive4!).toBe(BarBaz)
5656
})
57-
test('maybeSelfReference', async () => {
58-
let component1: Component | string
59-
let component2: Component | string
60-
let component3: Component | string
61-
const Foo = () => []
62-
const Root = define({
63-
name: 'Root',
64-
render() {
65-
component1 = resolveComponent('Root', true)
66-
component2 = resolveComponent('Foo', true)
67-
component3 = resolveComponent('Bar', true)
68-
return []
69-
},
70-
})
71-
const app = createVaporApp(Root.component)
72-
app.component('Foo', Foo)
73-
const root = document.createElement('div')
74-
app.mount(root)
75-
expect(component1!).toMatchObject(Root.component) // explicit self name reference
76-
expect(component2!).toBe(Foo) // successful resolve take higher priority
77-
expect(component3!).toMatchObject(Root.component) // fallback when resolve fails
78-
})
57+
7958
describe('warning', () => {
8059
test('used outside render() or setup()', () => {
8160
resolveComponent('foo')

packages/runtime-vapor/src/component.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -425,11 +425,10 @@ function getSlotsProxy(instance: ComponentInternalInstance): StaticSlots {
425425

426426
export function getComponentName(
427427
Component: Component,
428-
includeInferred = true,
429428
): string | false | undefined {
430429
return isFunction(Component)
431430
? Component.displayName || Component.name
432-
: Component.name || (includeInferred && Component.__name)
431+
: Component.name || Component.__name
433432
}
434433

435434
export function formatComponentName(

packages/runtime-vapor/src/helpers/resolveAssets.ts

+4-21
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@ export const DIRECTIVES = 'directives'
88

99
export type AssetTypes = typeof COMPONENTS | typeof DIRECTIVES
1010

11-
export function resolveComponent(
12-
name: string,
13-
maybeSelfReference?: boolean,
14-
): string | Component {
15-
return resolveAsset(COMPONENTS, name, true, maybeSelfReference) || name
11+
export function resolveComponent(name: string): string | Component {
12+
return resolveAsset(COMPONENTS, name, true) || name
1613
}
1714

1815
export function resolveDirective(name: string): Directive | undefined {
@@ -27,30 +24,21 @@ function resolveAsset(
2724
type: typeof COMPONENTS,
2825
name: string,
2926
warnMissing?: boolean,
30-
maybeSelfReference?: boolean,
3127
): Component | undefined
3228
// overload 2: directives
3329
function resolveAsset(
3430
type: typeof DIRECTIVES,
3531
name: string,
3632
): Directive | undefined
3733
// implementation
38-
function resolveAsset(
39-
type: AssetTypes,
40-
name: string,
41-
warnMissing = true,
42-
maybeSelfReference = false,
43-
) {
34+
function resolveAsset(type: AssetTypes, name: string, warnMissing = true) {
4435
const instance = currentInstance
4536
if (instance) {
4637
const Component = instance.type
4738

4839
// explicit self name has highest priority
4940
if (type === COMPONENTS) {
50-
const selfName = getComponentName(
51-
Component,
52-
false /* do not include inferred name to avoid breaking existing code */,
53-
)
41+
const selfName = getComponentName(Component)
5442
if (
5543
selfName &&
5644
(selfName === name ||
@@ -65,11 +53,6 @@ function resolveAsset(
6553
// global registration
6654
resolve(instance.appContext[type], name)
6755

68-
if (!res && maybeSelfReference) {
69-
// fallback to implicit self-reference
70-
return Component
71-
}
72-
7356
if (__DEV__ && warnMissing && !res) {
7457
const extra =
7558
type === COMPONENTS

0 commit comments

Comments
 (0)