Skip to content

Commit 4139e22

Browse files
committed
fix(slots): refine internal key checking logic
1 parent 347ef1d commit 4139e22

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

packages/runtime-core/__tests__/componentSlots.spec.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
nodeOps,
77
ref,
88
render,
9+
serializeInner,
910
useSlots,
1011
} from '@vue/runtime-test'
1112
import { createBlock, normalizeVNode } from '../src/vnode'
@@ -74,6 +75,10 @@ describe('component: slots', () => {
7475
footer: ['f1', 'f2'],
7576
})
7677

78+
expect(
79+
'[Vue warn]: Non-function value encountered for slot "_inner". Prefer function slots for better performance.',
80+
).toHaveBeenWarned()
81+
7782
expect(
7883
'[Vue warn]: Non-function value encountered for slot "header". Prefer function slots for better performance.',
7984
).toHaveBeenWarned()
@@ -82,8 +87,8 @@ describe('component: slots', () => {
8287
'[Vue warn]: Non-function value encountered for slot "footer". Prefer function slots for better performance.',
8388
).toHaveBeenWarned()
8489

85-
expect(slots).not.toHaveProperty('_inner')
8690
expect(slots).not.toHaveProperty('foo')
91+
expect(slots._inner()).toMatchObject([normalizeVNode('_inner')])
8792
expect(slots.header()).toMatchObject([normalizeVNode('header')])
8893
expect(slots.footer()).toMatchObject([
8994
normalizeVNode('f1'),
@@ -442,4 +447,22 @@ describe('component: slots', () => {
442447
'Slot "default" invoked outside of the render function',
443448
).toHaveBeenWarned()
444449
})
450+
451+
test('slot name starts with underscore', () => {
452+
const Comp = {
453+
setup(_: any, { slots }: any) {
454+
return () => slots._foo()
455+
},
456+
}
457+
458+
const App = {
459+
setup() {
460+
return () => h(Comp, null, { _foo: () => 'foo' })
461+
},
462+
}
463+
464+
const root = nodeOps.createElement('div')
465+
createApp(App).mount(root)
466+
expect(serializeInner(root)).toBe('foo')
467+
})
445468
})

packages/runtime-core/src/componentSlots.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ export type RawSlots = {
8686
__?: number[]
8787
}
8888

89-
const isInternalKey = (key: string) => key[0] === '_' || key === '$stable'
89+
const isInternalKey = (key: string) =>
90+
key === '_' || key === '__' || key === '_ctx' || key === '$stable'
9091

9192
const normalizeSlotValue = (value: unknown): VNode[] =>
9293
isArray(value)

0 commit comments

Comments
 (0)