Backtestsvuerun-20261005-155915#15048
Scoped slot transforms array argument if rendered conditionally
Our patch was judged better than the merged fix.
In this judgment, Patch A = our agent, Patch B = the merged fix.
Both patches fix the root cause the same way: the compiler-generated branch key becomes a separate 6th `renderSlot` argument instead of being merged into the slot props, so a single `v-bind` array reaches the slot unchanged. Both runtimes use that key for the fragment key and add it to the real `<slot>` element in custom-element mode.
Correctness: Patch A applies the new path only where the bug occurs, in `injectProp`, when the slot props are a single `v-bind` expression. Every other slot case keeps its existing codegen (plain object or object-literal injection), which lowers regression risk. Patch A also removes the `ref_for` marker from slot outlets. Without that, `<slot v-for v-bind="arr">` would still emit `mergeProps({ref_for: true}, arr)` and turn the array into an object, which is the same symptom in a sibling scenario. Patch B does not handle that case. Instead, Patch B routes every slot key injection through the new argument, which changes codegen even for slots that were never affected. B does keep user-key priority (`props.key || branchKey`), slightly closer to the old merge semantics. A gives the compiler key priority, a minor edge case.
Tests: Patch A adds compiler tests for v-if, template v-for and v-for slot cases. It also adds end-to-end compiler+runtime tests that check the slot receives a real array (`Array.isArray(list)` is true), that it survives toggling, and that v-if/v-else branch keys still cause a remount, plus a custom-element test. These would fail before the fix and target the reported behaviour directly. Patch B's tests are compiler snapshots plus unit tests of `renderSlot` with the new argument. They are reasonable but do not show the full compiled-template scenario working, and do not cover the v-for/`ref_for` variant.
Scope and craft: Patch B rewrites existing snapshots for unaffected cases and adds a stray `transformElement.spec.ts.snap` containing v-for snapshot content, which is churn and looks like a mistake. Patch A's change is localized and clearly commented.
Overall, Patch A is more targeted, covers more manifestations of the bug, and has stronger tests.
The judge saw only the two patches, labelled A and B in random order, with issue links and version numbers removed. The reasoning above is shown verbatim.
Solve
13m 29s
Wall-clock time in the container
Full test suite
No new failures
3,629 passed · 6 skipped · 3,635 total
Contamination audit
Clean
No sign the agent saw the real fix
Patch size
219vs 266 merged
Changed lines, ours vs merged
The issue
View on GitHubVue version
3.5.0
Link to minimal reproduction
Steps to reproduce
- Create a component with a scoped slot that is rendered conditionally
- Pass an array as the sole argument to the slot
What is expected?
Array is rendered normally.
If you render items of that array in v-for loop, you only see items inside that array
What is actually happening?
Array is transformed into object. Items and their indexes are staying the same, key field is added
<img width="383" height="111" alt="Image" src="https://github.com/user-attachments/assets/338bc873-5c20-4fb3-aed9-88f9f8e8cd98" />
System Info
Any additional comments?
key attribute is generated by the compiler for the slot rendered with v-if.
<img width="781" height="243" alt="Image" src="https://github.com/user-attachments/assets/99704cf9-71cb-435d-ba6f-92578b65ff5d" />
While this is not explicitly mentioned in documentation, one can assume that the expectation is that slotProps is always an object, as this is what will be passed to the slot if you use multiple v-bind directives on the slot.
This issue is rather pointing out the difference in behavior of the slot when v-if is present or not present.
The two patches
packages/compiler-core/__tests__/transforms/vFor.spec.tsindex 34991445c..94e669f53 100644@@ -18,7 +18,12 @@ import { } from '../../src/ast' import { ErrorCodes } from '../../src/errors' import { type CompilerOptions, generate } from '../../src'-import { FRAGMENT, RENDER_LIST, RENDER_SLOT } from '../../src/runtimeHelpers'+import {+ FRAGMENT,+ NORMALIZE_PROPS,+ RENDER_LIST,+ RENDER_SLOT,+} from '../../src/runtimeHelpers' import { PatchFlags } from '@vue/shared' import { createObjectMatcher } from '../testUtils' import { transformVBindShorthand } from '../../src/transforms/transformVBindShorthand'@@ -918,6 +923,48 @@ describe('compiler: v-for', () => { expect(generate(root).code).toMatchSnapshot() }) + test('template v-for key w/ <slot/> w/ single v-bind should not merge key into props', () => {+ const {+ root,+ node: { codegenNode },+ } = parseWithForTransform(+ '<template v-for="item in items" :key="item.id"><slot v-bind="item.list"/></template>',+ )+ expect(+ assertSharedCodegen(codegenNode, true, true /* custom return */),+ ).toMatchObject({+ returns: {+ type: NodeTypes.JS_CALL_EXPRESSION,+ callee: RENDER_SLOT,+ arguments: [+ '$slots',+ '"default"',+ { callee: NORMALIZE_PROPS },+ 'undefined',+ 'false',+ { content: 'item.id' },+ ],+ },+ })+ const code = generate(root).code+ expect(code).not.toMatch('mergeProps')+ expect(code).toMatch(+ `_renderSlot($slots, "default", _normalizeProps(_guardReactiveProps(item.list)), undefined, false, item.id)`,+ )+ })++ test('v-for on <slot/> w/ single v-bind should not merge ref_for into props', () => {+ const { root } = parseWithForTransform(+ '<slot v-for="item in items" v-bind="item.list"/>',+ )+ const code = generate(root).code+ expect(code).not.toMatch('mergeProps')+ expect(code).not.toMatch('ref_for')+ expect(code).toMatch(+ `_renderSlot($slots, "default", _normalizeProps(_guardReactiveProps(item.list)))`,+ )+ })+ // #1907 test('template v-for key injection with single child', () => { const {packages/compiler-core/__tests__/transforms/vIf.spec.tsindex fe3aef714..cda269d72 100644@@ -527,6 +527,30 @@ describe('compiler: v-if', () => { expect(generate(root).code).toMatchSnapshot() }) + test('v-if on <slot/> w/ single v-bind should not merge key into props', () => {+ const {+ root,+ node: { codegenNode },+ } = parseWithIfTransform(`<slot v-if="ok" v-bind="items"></slot>`)+ expect(codegenNode.consequent).toMatchObject({+ type: NodeTypes.JS_CALL_EXPRESSION,+ callee: RENDER_SLOT,+ arguments: [+ '$slots',+ '"default"',+ { callee: NORMALIZE_PROPS },+ 'undefined',+ 'false',+ { content: '0' },+ ],+ })+ const code = generate(root).code+ expect(code).not.toMatch('mergeProps')+ expect(code).toMatch(+ `_renderSlot($slots, "default", _normalizeProps(_guardReactiveProps(items)), undefined, false, 0)`,+ )+ })+ test('v-if + v-else', () => { const { root,packages/compiler-core/src/ast.tsindex e3cc5304d..b570689cf 100644@@ -497,6 +497,15 @@ export interface RenderSlotCall extends CallExpression { PropsExpression | '{}', TemplateChildNode[], ]+ // $slots, name, props, fallback, noSlotted, key+ | [+ string,+ string | ExpressionNode,+ PropsExpression | '{}',+ FunctionExpression | 'undefined',+ string,+ JSChildNode,+ ] } export type SlotsExpression = SlotsObjectExpression | DynamicSlotsExpressionpackages/compiler-core/src/transforms/transformElement.tsindex 40f08d45b..8b21eea55 100644@@ -51,6 +51,7 @@ import { import { findProp, isCoreComponent,+ isSlotOutlet, isStaticArgOf, isStaticExp, toValidAssetId,@@ -638,7 +639,11 @@ export function buildProps( } // #10696 in case a v-bind object contains ref- pushRefVForMarker()+ // slot outlets don't support refs, and their props are passed to+ // the slot as-is, so the marker must not be merged into them+ if (!isSlotOutlet(node)) {+ pushRefVForMarker()+ } pushMergeArg() mergeArgs.push(exp) } else {packages/compiler-core/src/utils.tsindex aa426bbab..8be244e55 100644@@ -445,6 +445,16 @@ export function injectProp( props.properties.unshift(prop) } propsWithInjection = props+ } else if (node.type === NodeTypes.JS_CALL_EXPRESSION) {+ // single v-bind with expression on a slot outlet, e.g.+ // <slot v-if="ok" v-bind="items" />. The value is passed to the slot+ // as-is (it may be an array), so merging the key into it would alter what+ // the slot receives. Pass the key as a separate renderSlot argument.+ const args = node.arguments as CallExpression['arguments']+ if (args.length < 4) args[3] = 'undefined' // fallback+ if (args.length < 5) args[4] = 'false' // noSlotted+ args[5] = prop.value+ return } else { // single v-bind with expression, return a merged replacement propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [packages/runtime-core/src/helpers/renderSlot.tsindex 8f65f8af4..03370f851 100644@@ -16,7 +16,7 @@ import { isVNode, openBlock, } from '../vnode'-import { PatchFlags, SlotFlags, isSymbol } from '@vue/shared'+import { PatchFlags, SlotFlags, extend, isSymbol } from '@vue/shared' import { warn } from '../warning' import { isAsyncWrapper } from '../apiAsyncComponent' @@ -32,6 +32,9 @@ export function renderSlot( // the compiler and guaranteed to be a function returning an array fallback?: () => VNodeArrayChildren, noSlotted?: boolean,+ // branch key generated by the compiler for slot outlets whose props are a+ // single `v-bind` expression (which must be passed to the slot unmodified)+ key?: PropertyKey, ): VNode { if ( currentRenderingInstance!.ce ||@@ -39,6 +42,8 @@ export function renderSlot( isAsyncWrapper(currentRenderingInstance!.parent) && currentRenderingInstance!.parent.ce) ) {+ // apply the compiler-generated branch key to the actual slot element+ if (key != null) props = extend({ key }, props) const hasProps = Object.keys(props).length > 0 // in custom element mode, render <slot/> as actual slot outlets // wrap it with a fragment because in shadowRoot: false mode the slot@@ -79,7 +84,7 @@ export function renderSlot( try { const validSlotContent = slot && ensureValidVNode(slot(props)) const slotKey =- props.key ||+ (key != null ? 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)packages/runtime-dom/__tests__/customElement.spec.tsindex a5bea20b8..f59b2d5e2 100644@@ -915,6 +915,26 @@ describe('defineCustomElement', () => { `<div><slot class="bar"></slot></div>`, ) })++ test('render conditional slots with branch key and single v-bind', async () => {+ const ok = ref(true)+ const E = defineCustomElement({+ render() {+ // compiled from <slot v-if="ok" v-bind="{}">A</slot><slot v-else v-bind="{}">B</slot>+ return ok.value+ ? renderSlot(this.$slots, 'default', {}, () => ['A'], false, 0)+ : renderSlot(this.$slots, 'default', {}, () => ['B'], false, 1)+ },+ })+ customElements.define('my-el-slot-branch-key', E)+ container.innerHTML = `<my-el-slot-branch-key></my-el-slot-branch-key>`+ const e = container.childNodes[0] as VueElement+ expect(e.shadowRoot!.innerHTML).toBe(`<slot>A</slot>`)++ ok.value = false+ await nextTick()+ expect(e.shadowRoot!.innerHTML).toBe(`<slot>B</slot>`)+ }) }) describe('provide/inject', () => {packages/vue/__tests__/index.spec.tsindex 6eeff41dd..668e381d2 100644@@ -303,6 +303,97 @@ describe('compiler + runtime integration', () => { expect(EMPTY_ARR.length).toBe(0) }) + test('<slot v-if> with single v-bind array should pass the array as-is', async () => {+ const ok = ref(true)+ const Comp = {+ props: ['items', 'ok'],+ template: `<slot v-if="ok" v-bind="items" />`,+ }+ const App = {+ components: { Comp },+ setup: () => ({ ok }),+ template:+ `<Comp :items="['a', 'b']" :ok="ok" v-slot="list">` ++ `<span v-for="i in list">{{ i }}</span>` ++ `{{ Array.isArray(list) }}</Comp>`,+ }+ const root = document.createElement('div')+ createApp(App).mount(root)+ expect(root.innerHTML).toBe('<span>a</span><span>b</span>true')++ ok.value = false+ await nextTick()+ expect(root.innerHTML).toBe('<!--v-if-->')++ ok.value = true+ await nextTick()+ expect(root.innerHTML).toBe('<span>a</span><span>b</span>true')+ })++ test('<slot v-if>/<slot v-else> with single v-bind should keep branch keys', async () => {+ const ok = ref(true)+ const mounted = vi.fn()+ const Child = {+ props: ['list'],+ mounted,+ template: `<span>{{ list.join() }}</span>`,+ }+ const Comp = {+ props: ['ok'],+ template:+ `<slot v-if="ok" v-bind="['a']" />` + `<slot v-else v-bind="['b']" />`,+ }+ const App = {+ components: { Comp, Child },+ setup: () => ({ ok }),+ template: `<Comp :ok="ok" v-slot="list"><Child :list="list" /></Comp>`,+ }+ const root = document.createElement('div')+ createApp(App).mount(root)+ expect(root.innerHTML).toBe('<span>a</span>')+ expect(mounted).toHaveBeenCalledTimes(1)++ ok.value = false+ await nextTick()+ expect(root.innerHTML).toBe('<span>b</span>')+ // different branch keys -> slot content is remounted+ expect(mounted).toHaveBeenCalledTimes(2)+ })++ test('<template v-for :key><slot v-bind> with array should pass the array as-is', () => {+ const Comp = {+ props: ['groups'],+ template:+ `<template v-for="g in groups" :key="g.id">` ++ `<slot v-bind="g.items" /></template>`,+ }+ const App = {+ components: { Comp },+ template:+ `<Comp :groups="[{ id: 1, items: ['a', 'b'] }, { id: 2, items: ['c'] }]" v-slot="list">` ++ `[<i v-for="i in list">{{ i }}</i>{{ Array.isArray(list) }}]</Comp>`,+ }+ const root = document.createElement('div')+ createApp(App).mount(root)+ expect(root.innerHTML).toBe('[<i>a</i><i>b</i>true][<i>c</i>true]')+ })++ test('<slot v-for v-bind> with array should pass the array as-is', () => {+ const Comp = {+ props: ['groups'],+ template: `<slot v-for="g in groups" v-bind="g" />`,+ }+ const App = {+ components: { Comp },+ template:+ `<Comp :groups="[['a', 'b'], ['c']]" v-slot="list">` ++ `[<i v-for="i in list">{{ i }}</i>{{ Array.isArray(list) }}]</Comp>`,+ }+ const root = document.createElement('div')+ createApp(App).mount(root)+ expect(root.innerHTML).toBe('[<i>a</i><i>b</i>true][<i>c</i>true]')+ })+ test('BigInt support', () => { const app = createApp({ template: `<div>{{ BigInt(BigInt(100000111)) + BigInt(2000000000n) * 30000000n }}</div>`,
packages/compiler-core/__tests__/transforms/__snapshots__/transformElement.spec.ts.snapindex 3da778eb6..c07237de2 100644@@ -121,6 +121,20 @@ return function render(_ctx, _cache) { }" `; +exports[`compiler: v-for > codegen > template v-for key injection with single slot child 1`] = `+"const _Vue = Vue++return function render(_ctx, _cache) {+ with (_ctx) {+ const { renderList: _renderList, Fragment: _Fragment, openBlock: _openBlock, createElementBlock: _createElementBlock, renderSlot: _renderSlot } = _Vue++ return (_openBlock(true), _createElementBlock(_Fragment, null, _renderList(items, (item) => {+ return _renderSlot($slots, "default", {}, undefined, undefined, item.id)+ }), 128 /* KEYED_FRAGMENT */))+ }+}"+`;+ exports[`compiler: v-for > codegen > template v-for w/ <slot/> 1`] = ` "const _Vue = Vue packages/compiler-core/__tests__/transforms/__snapshots__/vFor.spec.ts.snapindex 3da778eb6..c07237de2 100644@@ -121,6 +121,20 @@ return function render(_ctx, _cache) { }" `; +exports[`compiler: v-for > codegen > template v-for key injection with single slot child 1`] = `+"const _Vue = Vue++return function render(_ctx, _cache) {+ with (_ctx) {+ const { renderList: _renderList, Fragment: _Fragment, openBlock: _openBlock, createElementBlock: _createElementBlock, renderSlot: _renderSlot } = _Vue++ return (_openBlock(true), _createElementBlock(_Fragment, null, _renderList(items, (item) => {+ return _renderSlot($slots, "default", {}, undefined, undefined, item.id)+ }), 128 /* KEYED_FRAGMENT */))+ }+}"+`;+ exports[`compiler: v-for > codegen > template v-for w/ <slot/> 1`] = ` "const _Vue = Vue packages/compiler-core/__tests__/transforms/__snapshots__/vIf.spec.ts.snapindex 65ee73c46..ed2c8e540 100644@@ -80,7 +80,7 @@ return function render(_ctx, _cache) { const { renderSlot: _renderSlot, createCommentVNode: _createCommentVNode } = _Vue return ok- ? _renderSlot($slots, "default", { key: 0 })+ ? _renderSlot($slots, "default", {}, undefined, undefined, 0) : _createCommentVNode("v-if", true) } }"@@ -140,7 +140,21 @@ return function render(_ctx, _cache) { const { renderSlot: _renderSlot, createCommentVNode: _createCommentVNode } = _Vue return ok- ? _renderSlot($slots, "default", { key: 0 })+ ? _renderSlot($slots, "default", {}, undefined, undefined, 0)+ : _createCommentVNode("v-if", true)+ }+}"+`;++exports[`compiler: v-if > codegen > v-if on <slot/> with v-bind 1`] = `+"const _Vue = Vue++return function render(_ctx, _cache) {+ with (_ctx) {+ const { normalizeProps: _normalizeProps, guardReactiveProps: _guardReactiveProps, renderSlot: _renderSlot, createCommentVNode: _createCommentVNode } = _Vue++ return ok+ ? _renderSlot($slots, "default", _normalizeProps(_guardReactiveProps(items)), undefined, undefined, 0) : _createCommentVNode("v-if", true) } }"packages/compiler-core/__tests__/transforms/vFor.spec.tsindex 34991445c..839d9d358 100644@@ -918,6 +918,34 @@ describe('compiler: v-for', () => { expect(generate(root).code).toMatchSnapshot() }) + test('template v-for key injection with single slot child', () => {+ const {+ root,+ node: { codegenNode },+ } = parseWithForTransform(+ '<template v-for="item in items" :key="item.id"><slot/></template>',+ )+ expect(+ assertSharedCodegen(codegenNode, true, true /* custom return */),+ ).toMatchObject({+ source: { content: `items` },+ params: [{ content: `item` }],+ returns: {+ type: NodeTypes.JS_CALL_EXPRESSION,+ callee: RENDER_SLOT,+ arguments: [+ '$slots',+ '"default"',+ '{}',+ 'undefined',+ 'undefined',+ { content: 'item.id' },+ ],+ },+ })+ expect(generate(root).code).toMatchSnapshot()+ })+ // #1907 test('template v-for key injection with single child', () => { const {packages/compiler-core/__tests__/transforms/vIf.spec.tsindex fe3aef714..677f6b55b 100644@@ -3,6 +3,7 @@ import { transform } from '../../src/transform' import { transformIf } from '../../src/transforms/vIf' import { transformElement } from '../../src/transforms/transformElement' import { transformSlotOutlet } from '../../src/transforms/transformSlotOutlet'+import { transformBind } from '../../src/transforms/vBind' import { type CommentNode, type ConditionalExpression,@@ -509,7 +510,14 @@ describe('compiler: v-if', () => { expect(codegenNode.consequent).toMatchObject({ type: NodeTypes.JS_CALL_EXPRESSION, callee: RENDER_SLOT,- arguments: ['$slots', '"default"', createObjectMatcher({ key: `[0]` })],+ arguments: [+ '$slots',+ '"default"',+ '{}',+ 'undefined',+ 'undefined',+ { content: '0' },+ ], }) expect(generate(root).code).toMatchSnapshot() })@@ -522,7 +530,41 @@ describe('compiler: v-if', () => { expect(codegenNode.consequent).toMatchObject({ type: NodeTypes.JS_CALL_EXPRESSION, callee: RENDER_SLOT,- arguments: ['$slots', '"default"', createObjectMatcher({ key: `[0]` })],+ arguments: [+ '$slots',+ '"default"',+ '{}',+ 'undefined',+ 'undefined',+ { content: '0' },+ ],+ })+ expect(generate(root).code).toMatchSnapshot()+ })++ test('v-if on <slot/> with v-bind', () => {+ const {+ root,+ node: { codegenNode },+ } = parseWithIfTransform(`<slot v-if="ok" v-bind="items"></slot>`, {+ directiveTransforms: {+ bind: transformBind,+ },+ })+ expect(codegenNode.consequent).toMatchObject({+ type: NodeTypes.JS_CALL_EXPRESSION,+ callee: RENDER_SLOT,+ arguments: [+ '$slots',+ '"default"',+ {+ type: NodeTypes.JS_CALL_EXPRESSION,+ callee: NORMALIZE_PROPS,+ },+ 'undefined',+ 'undefined',+ { content: '0' },+ ], }) expect(generate(root).code).toMatchSnapshot() })packages/compiler-core/src/ast.tsindex e3cc5304d..e6da01edb 100644@@ -488,14 +488,29 @@ export interface DirectiveArgumentNode extends ArrayExpression { export interface RenderSlotCall extends CallExpression { callee: typeof RENDER_SLOT arguments:- // $slots, name, props, fallback+ // $slots, name, props, fallback, noSlotted, branchKey | [string, string | ExpressionNode]- | [string, string | ExpressionNode, PropsExpression]+ | [string, string | ExpressionNode, PropsExpression | '{}'] | [ string, string | ExpressionNode, PropsExpression | '{}',- TemplateChildNode[],+ FunctionExpression | string,+ ]+ | [+ string,+ string | ExpressionNode,+ PropsExpression | '{}',+ FunctionExpression | string,+ string,+ ]+ | [+ string,+ string | ExpressionNode,+ PropsExpression | '{}',+ FunctionExpression | string,+ string,+ JSChildNode, ] } packages/compiler-core/src/utils.tsindex aa426bbab..025f6c32d 100644@@ -392,6 +392,10 @@ export function injectProp( prop: Property, context: TransformContext, ): void {+ if (node.type !== NodeTypes.VNODE_CALL && injectSlotKey(node, prop)) {+ return+ }+ let propsWithInjection: ObjectExpression | CallExpression | undefined /** * 1. mergeProps(...)@@ -473,6 +477,36 @@ export function injectProp( } } +function injectSlotKey(node: RenderSlotCall, prop: Property): boolean {+ if (+ prop.key.type !== NodeTypes.SIMPLE_EXPRESSION ||+ prop.key.content !== 'key'+ ) {+ return false+ }++ // If the slot already has a user-provided key, avoid injecting the branch+ // key so the user key keeps its existing priority.+ const props = node.arguments[2]+ if (props && !isString(props)) {+ const [unnormalizedProps] = getUnnormalizedProps(props as PropsExpression)+ if (+ unnormalizedProps &&+ !isString(unnormalizedProps) &&+ unnormalizedProps.type === NodeTypes.JS_OBJECT_EXPRESSION &&+ hasProp(prop, unnormalizedProps)+ ) {+ return true+ }+ }++ node.arguments[2] ||= '{}'+ node.arguments[3] ||= 'undefined'+ node.arguments[4] ||= 'undefined'+ node.arguments[5] = prop.value+ return true+}+ // check existing key to avoid overriding user provided keys function hasProp(prop: Property, props: ObjectExpression) { let result = falsepackages/runtime-core/__tests__/helpers/renderSlot.spec.tsindex bc0678b51..f359f431c 100644@@ -38,6 +38,83 @@ describe('renderSlot', () => { expect(vnode.key).toBe('_default') }) + it('should allow symbol values for compiler-injected slot keys', () => {+ const key = Symbol()+ const vnode = renderSlot(+ { default: () => [h('div')] },+ 'default',+ {},+ undefined,+ undefined,+ key,+ )+ expect(vnode.key).toBe('_default')+ })++ it('should not expose compiler-injected slot keys to slot props', () => {+ let receivedProps: any+ const props = ['foo', 'bar']+ const vnode = renderSlot(+ {+ default: props => {+ receivedProps = props+ return [h('div')]+ },+ },+ 'default',+ props as any,+ undefined,+ undefined,+ 'branch',+ )++ expect(receivedProps).toBe(props)+ expect(receivedProps).not.toHaveProperty('key')+ expect(vnode.key).toBe('branch')+ })++ it('should prefer user-provided slot prop keys over compiler-injected keys', () => {+ let receivedProps: any+ const props = { key: 'user' }+ const vnode = renderSlot(+ {+ default: props => {+ receivedProps = props+ return [h('div')]+ },+ },+ 'default',+ props,+ undefined,+ undefined,+ 'branch',+ )++ expect(receivedProps).toBe(props)+ expect(vnode.key).toBe('user')+ })++ it('should preserve compiler-injected slot keys in custom element mode', () => {+ setCurrentRenderingInstance({ type: {}, ce: {} } as any)++ let vnode = renderSlot({}, 'default', {}, undefined, undefined, 0)+ let slot = (vnode.children as any[])[0]+ expect(slot.type).toBe('slot')+ expect(slot.key).toBe(0)+ expect(vnode.patchFlag).toBe(PatchFlags.BAIL)++ vnode = renderSlot(+ {},+ 'default',+ { key: 'user' },+ undefined,+ undefined,+ 'branch',+ )+ slot = (vnode.children as any[])[0]+ expect(slot.key).toBe('user')+ })+ it('should render slot fallback', () => { const vnode = renderSlot({}, 'default', { key: 'foo' }, () => ['fallback']) expect(vnode.children).toEqual(['fallback'])packages/runtime-core/src/helpers/renderSlot.tsindex 8f65f8af4..2a68ee3e4 100644@@ -16,7 +16,7 @@ import { isVNode, openBlock, } from '../vnode'-import { PatchFlags, SlotFlags, isSymbol } from '@vue/shared'+import { PatchFlags, SlotFlags, extend, isSymbol } from '@vue/shared' import { warn } from '../warning' import { isAsyncWrapper } from '../apiAsyncComponent' @@ -32,6 +32,7 @@ export function renderSlot( // the compiler and guaranteed to be a function returning an array fallback?: () => VNodeArrayChildren, noSlotted?: boolean,+ branchKey?: PropertyKey, ): VNode { if ( currentRenderingInstance!.ce ||@@ -39,17 +40,21 @@ export function renderSlot( isAsyncWrapper(currentRenderingInstance!.parent) && currentRenderingInstance!.parent.ce) ) {- const hasProps = Object.keys(props).length > 0+ const slotProps =+ branchKey != null && props.key == null+ ? extend({}, props, { key: branchKey })+ : props+ const hasProps = Object.keys(slotProps).length > 0 // in custom element mode, render <slot/> as actual slot outlets // wrap it with a fragment because in shadowRoot: false mode the slot // element gets replaced by injected content- if (name !== 'default') props.name = name+ if (name !== 'default') slotProps.name = name return ( openBlock(), createBlock( Fragment, null,- [createVNode('slot', props, fallback && fallback())],+ [createVNode('slot', slotProps, fallback && fallback())], hasProps ? PatchFlags.BAIL : PatchFlags.STABLE_FRAGMENT, ) )@@ -80,6 +85,7 @@ export function renderSlot( const validSlotContent = slot && ensureValidVNode(slot(props)) const slotKey = props.key ||+ branchKey || // 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)