Skip to content

Commit

Permalink
fix(runtime-core): allow symbol values for slot prop key (#12069)
Browse files Browse the repository at this point in the history
close #12068
  • Loading branch information
jh-leong authored Oct 11, 2024
1 parent e16e9a7 commit d9d4d4e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
6 changes: 6 additions & 0 deletions packages/runtime-core/__tests__/helpers/renderSlot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ describe('renderSlot', () => {
expect(vnode.key).toBe('foo')
})

it('should allow symbol values for slot prop key', () => {
const key = Symbol()
const vnode = renderSlot({ default: () => [h('div')] }, 'default', { key })
expect(vnode.key).toBe('_default')
})

it('should render slot fallback', () => {
const vnode = renderSlot({}, 'default', { key: 'foo' }, () => ['fallback'])
expect(vnode.children).toEqual(['fallback'])
Expand Down
13 changes: 7 additions & 6 deletions packages/runtime-core/src/helpers/renderSlot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
isVNode,
openBlock,
} from '../vnode'
import { PatchFlags, SlotFlags } from '@vue/shared'
import { PatchFlags, SlotFlags, isSymbol } from '@vue/shared'
import { warn } from '../warning'
import { isAsyncWrapper } from '../apiAsyncComponent'

Expand Down Expand Up @@ -72,15 +72,16 @@ export function renderSlot(
}
openBlock()
const validSlotContent = slot && ensureValidVNode(slot(props))
const slotKey =
props.key ||
// slot content array of a dynamic conditional slot may have a branch
// key attached in the `createSlots` helper, respect that
(validSlotContent && (validSlotContent as any).key)
const rendered = createBlock(
Fragment,
{
key:
(props.key ||
// slot content array of a dynamic conditional slot may have a branch
// key attached in the `createSlots` helper, respect that
(validSlotContent && (validSlotContent as any).key) ||
`_${name}`) +
(slotKey && !isSymbol(slotKey) ? slotKey : `_${name}`) +
// #7256 force differentiate fallback content from actual content
(!validSlotContent && fallback ? '_fb' : ''),
},
Expand Down

0 comments on commit d9d4d4e

Please sign in to comment.