]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-core): allow symbol values for slot prop key (#12069)
authorTycho <jh.leong@outlook.com>
Fri, 11 Oct 2024 02:28:54 +0000 (10:28 +0800)
committerGitHub <noreply@github.com>
Fri, 11 Oct 2024 02:28:54 +0000 (10:28 +0800)
close #12068

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

index c4ae077ba347e79e461e6b1b0c34e247c6444704..bc0678b51c91e4b2c1f8204dff6e6d3f4b8d977f 100644 (file)
@@ -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'])
index 2cb266ef1c4b301149a3f520ffee754b10d506bd..92f7dab36b621f2be3cf2b7a49ea2e9b066f6123 100644 (file)
@@ -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'
 
@@ -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' : ''),
     },