Skip to content

Commit d9d4d4e

Browse files
authored
fix(runtime-core): allow symbol values for slot prop key (#12069)
close #12068
1 parent e16e9a7 commit d9d4d4e

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

packages/runtime-core/__tests__/helpers/renderSlot.spec.ts

+6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ describe('renderSlot', () => {
3232
expect(vnode.key).toBe('foo')
3333
})
3434

35+
it('should allow symbol values for slot prop key', () => {
36+
const key = Symbol()
37+
const vnode = renderSlot({ default: () => [h('div')] }, 'default', { key })
38+
expect(vnode.key).toBe('_default')
39+
})
40+
3541
it('should render slot fallback', () => {
3642
const vnode = renderSlot({}, 'default', { key: 'foo' }, () => ['fallback'])
3743
expect(vnode.children).toEqual(['fallback'])

packages/runtime-core/src/helpers/renderSlot.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
isVNode,
1515
openBlock,
1616
} from '../vnode'
17-
import { PatchFlags, SlotFlags } from '@vue/shared'
17+
import { PatchFlags, SlotFlags, isSymbol } from '@vue/shared'
1818
import { warn } from '../warning'
1919
import { isAsyncWrapper } from '../apiAsyncComponent'
2020

@@ -72,15 +72,16 @@ export function renderSlot(
7272
}
7373
openBlock()
7474
const validSlotContent = slot && ensureValidVNode(slot(props))
75+
const slotKey =
76+
props.key ||
77+
// slot content array of a dynamic conditional slot may have a branch
78+
// key attached in the `createSlots` helper, respect that
79+
(validSlotContent && (validSlotContent as any).key)
7580
const rendered = createBlock(
7681
Fragment,
7782
{
7883
key:
79-
(props.key ||
80-
// slot content array of a dynamic conditional slot may have a branch
81-
// key attached in the `createSlots` helper, respect that
82-
(validSlotContent && (validSlotContent as any).key) ||
83-
`_${name}`) +
84+
(slotKey && !isSymbol(slotKey) ? slotKey : `_${name}`) +
8485
// #7256 force differentiate fallback content from actual content
8586
(!validSlotContent && fallback ? '_fb' : ''),
8687
},

0 commit comments

Comments
 (0)