mirror of https://github.com/vuejs/core.git
fix(slots): refine internal key checking logic
This commit is contained in:
parent
347ef1d3f5
commit
4139e22385
|
@ -6,6 +6,7 @@ import {
|
|||
nodeOps,
|
||||
ref,
|
||||
render,
|
||||
serializeInner,
|
||||
useSlots,
|
||||
} from '@vue/runtime-test'
|
||||
import { createBlock, normalizeVNode } from '../src/vnode'
|
||||
|
@ -74,6 +75,10 @@ describe('component: slots', () => {
|
|||
footer: ['f1', 'f2'],
|
||||
})
|
||||
|
||||
expect(
|
||||
'[Vue warn]: Non-function value encountered for slot "_inner". Prefer function slots for better performance.',
|
||||
).toHaveBeenWarned()
|
||||
|
||||
expect(
|
||||
'[Vue warn]: Non-function value encountered for slot "header". Prefer function slots for better performance.',
|
||||
).toHaveBeenWarned()
|
||||
|
@ -82,8 +87,8 @@ describe('component: slots', () => {
|
|||
'[Vue warn]: Non-function value encountered for slot "footer". Prefer function slots for better performance.',
|
||||
).toHaveBeenWarned()
|
||||
|
||||
expect(slots).not.toHaveProperty('_inner')
|
||||
expect(slots).not.toHaveProperty('foo')
|
||||
expect(slots._inner()).toMatchObject([normalizeVNode('_inner')])
|
||||
expect(slots.header()).toMatchObject([normalizeVNode('header')])
|
||||
expect(slots.footer()).toMatchObject([
|
||||
normalizeVNode('f1'),
|
||||
|
@ -442,4 +447,22 @@ describe('component: slots', () => {
|
|||
'Slot "default" invoked outside of the render function',
|
||||
).toHaveBeenWarned()
|
||||
})
|
||||
|
||||
test('slot name starts with underscore', () => {
|
||||
const Comp = {
|
||||
setup(_: any, { slots }: any) {
|
||||
return () => slots._foo()
|
||||
},
|
||||
}
|
||||
|
||||
const App = {
|
||||
setup() {
|
||||
return () => h(Comp, null, { _foo: () => 'foo' })
|
||||
},
|
||||
}
|
||||
|
||||
const root = nodeOps.createElement('div')
|
||||
createApp(App).mount(root)
|
||||
expect(serializeInner(root)).toBe('foo')
|
||||
})
|
||||
})
|
||||
|
|
|
@ -86,7 +86,8 @@ export type RawSlots = {
|
|||
__?: number[]
|
||||
}
|
||||
|
||||
const isInternalKey = (key: string) => key[0] === '_' || key === '$stable'
|
||||
const isInternalKey = (key: string) =>
|
||||
key === '_' || key === '__' || key === '_ctx' || key === '$stable'
|
||||
|
||||
const normalizeSlotValue = (value: unknown): VNode[] =>
|
||||
isArray(value)
|
||||
|
|
Loading…
Reference in New Issue