Backtestsvuerun-20261002-115633#15048

Issue #15048 Merged fix PR #15051 Run 2 Oct 2026 · run-20261002-115633 vuejs/core

Scoped slot transforms array argument if rendered conditionally

Better

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 stops merging the branch key into a single `v-bind` value on `<slot>`, passes it as a new sixth `renderSlot()` argument, and the runtime uses that argument for the fragment key. Both also handle custom-element mode by copying props before applying the key.

Correctness edges:
- Patch A limits the new branch in `injectProp` to the single-`v-bind`-expression case, the only case where merging corrupts the slot props. Object-literal props and `mergeProps` keep their existing behavior and snapshots.
- Patch A also fixes the closely related `<slot v-for v-bind="item">` case. There, the `ref_for` marker was being merged into the `v-bind` value, which would turn an array into an object in the same way.
- Patch A adds a guard so a nullish `v-bind` value (e.g. `v-bind="null"`) does not crash. With the key no longer merged in by `mergeProps`, `props` could now be null where it previously was not.
- Patch B rewrites key injection for every `renderSlot` call, changing existing codegen for plain `<slot v-if>` (`{}` plus a positional key). That is broader churn with no extra benefit.
- Patch B does not handle the `v-for` `ref_for` case.
- Under Patch B, `<slot v-if v-bind="null">` would now reach `props.key` with null props and throw, a regression from the old `mergeProps` behavior.
- Patch B's user-key priority check and `RenderSlotCall` type updates are reasonable but secondary.

Tests:
- Patch A adds compiler tests for `v-if`, template `v-if`, keyed template `v-for`, and `v-for` on a slot. It also adds end-to-end compiler+runtime integration tests that reproduce the issue (array stays an array after toggling, `v-if`/`v-else`, keyed `v-for`, nullish binding) and a custom-element test.
- Patch B adds compiler tests and unit tests of `renderSlot`, but no end-to-end test of the reported scenario.

Overall, Patch A is more targeted, covers more of the related failure modes, and is better tested.

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

17m 42s

Wall-clock time in the container

Full test suite

No new failures

3,631 passed · 6 skipped · 3,637 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

367vs 266 merged

Changed lines, ours vs merged

Vue version

3.5.0

Link to minimal reproduction

https://play.vuejs.org/#eNqFUk1v00AQ/SvDXgxSYqsEDgSnEqBKwAEQReLAoiq1J+m2+6XdtZvK8n/v7Dp2oyptb7Pz3s68mTcd+2Rt3jbIlqz0lRM2gMfQ2FOuhbLGBejA4QZ62DijICNqNkFfjLL7fF7ER6yUfeSa68poH0D5Lazi/9fZV5TSwF/jZP0qe8N1WQztqBE9Aior1wHpBVCmuu3cSxNWnAkCPWcJAug6SAno+8RNfQkri4MabMaCJwkbsc2vvdE0XRfZnFXEFhLdTxsESeRsCQmJ2JoU3n5PueAanI356gqrmyP5a7+LOc5+OfToWuRswsLabTEM8Nn5D9xRPIHK1I0k9jPgb/RGNlHjQPvc6JpkH/CS2m/JCKG3f/zZLqD241BRaGT2ic8ZGRMX9dToD3IX+bv0j+uetjiaeuQ8BocHL1bwL4vRSTaDFLwdg0X2n+7hObNr0e6tLb1d69Nzcp1ORtfosAZtnKJJ76hCBMtLB8VEj8x2fil0/XAme7gsxrqxAfhwJ5FIiuYUeh6MXcKJQzWd1bHeNGEt4q5eECA2B+1f0PP4TC9adNE0WvAif58vPrD+HmmCLos=

Steps to reproduce

  1. Create a component with a scoped slot that is rendered conditionally
  2. 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

Our patch+364 −3
packages/compiler-core/__tests__/transforms/__snapshots__/transformElement.spec.ts.snapindex 3da778eb6..11cbe78e2 100644@@ -31,6 +31,20 @@ return function render(_ctx, _cache) { }" `; +exports[`compiler: v-for > codegen > keyed template v-for w/ <slot/> w/ single v-bind 1`] = `+"const _Vue = Vue++return function render(_ctx, _cache) {+  with (_ctx) {+    const { renderList: _renderList, Fragment: _Fragment, openBlock: _openBlock, createElementBlock: _createElementBlock, normalizeProps: _normalizeProps, guardReactiveProps: _guardReactiveProps, renderSlot: _renderSlot } = _Vue++    return (_openBlock(true), _createElementBlock(_Fragment, null, _renderList(items, (item) => {+      return _renderSlot($slots, "default", _normalizeProps(_guardReactiveProps(item.list)), undefined, undefined, item.id)+    }), 128 /* KEYED_FRAGMENT */))+  }+}"+`;+ exports[`compiler: v-for > codegen > keyed v-for 1`] = ` "const _Vue = Vue @@ -149,6 +163,20 @@ return function render(_ctx, _cache) { }" `; +exports[`compiler: v-for > codegen > v-for on <slot/> w/ single v-bind 1`] = `+"const _Vue = Vue++return function render(_ctx, _cache) {+  with (_ctx) {+    const { renderList: _renderList, Fragment: _Fragment, openBlock: _openBlock, createElementBlock: _createElementBlock, normalizeProps: _normalizeProps, guardReactiveProps: _guardReactiveProps, renderSlot: _renderSlot } = _Vue++    return (_openBlock(true), _createElementBlock(_Fragment, null, _renderList(items, (item) => {+      return _renderSlot($slots, "default", _normalizeProps(_guardReactiveProps(item)))+    }), 256 /* UNKEYED_FRAGMENT */))+  }+}"+`;+ exports[`compiler: v-for > codegen > v-for on element with custom directive 1`] = ` "const _Vue = Vue packages/compiler-core/__tests__/transforms/__snapshots__/vFor.spec.ts.snapindex 3da778eb6..11cbe78e2 100644@@ -31,6 +31,20 @@ return function render(_ctx, _cache) { }" `; +exports[`compiler: v-for > codegen > keyed template v-for w/ <slot/> w/ single v-bind 1`] = `+"const _Vue = Vue++return function render(_ctx, _cache) {+  with (_ctx) {+    const { renderList: _renderList, Fragment: _Fragment, openBlock: _openBlock, createElementBlock: _createElementBlock, normalizeProps: _normalizeProps, guardReactiveProps: _guardReactiveProps, renderSlot: _renderSlot } = _Vue++    return (_openBlock(true), _createElementBlock(_Fragment, null, _renderList(items, (item) => {+      return _renderSlot($slots, "default", _normalizeProps(_guardReactiveProps(item.list)), undefined, undefined, item.id)+    }), 128 /* KEYED_FRAGMENT */))+  }+}"+`;+ exports[`compiler: v-for > codegen > keyed v-for 1`] = ` "const _Vue = Vue @@ -149,6 +163,20 @@ return function render(_ctx, _cache) { }" `; +exports[`compiler: v-for > codegen > v-for on <slot/> w/ single v-bind 1`] = `+"const _Vue = Vue++return function render(_ctx, _cache) {+  with (_ctx) {+    const { renderList: _renderList, Fragment: _Fragment, openBlock: _openBlock, createElementBlock: _createElementBlock, normalizeProps: _normalizeProps, guardReactiveProps: _guardReactiveProps, renderSlot: _renderSlot } = _Vue++    return (_openBlock(true), _createElementBlock(_Fragment, null, _renderList(items, (item) => {+      return _renderSlot($slots, "default", _normalizeProps(_guardReactiveProps(item)))+    }), 256 /* UNKEYED_FRAGMENT */))+  }+}"+`;+ exports[`compiler: v-for > codegen > v-for on element with custom directive 1`] = ` "const _Vue = Vue packages/compiler-core/__tests__/transforms/__snapshots__/vIf.spec.ts.snapindex 65ee73c46..c6d42b605 100644@@ -145,3 +145,31 @@ return function render(_ctx, _cache) {   } }" `;++exports[`compiler: v-if > transform > template v-if w/ single <slot/> child w/ single 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)), () => ["fallback"], undefined, 0)+      : _createCommentVNode("v-if", true)+  }+}"+`;++exports[`compiler: v-if > transform > v-if on <slot/> w/ single 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..6586ef1fc 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'@@ -941,6 +946,61 @@ describe('compiler: v-for', () => {       expect(generate(root).code).toMatchSnapshot()     }) +    test('keyed template v-for w/ <slot/> w/ single v-bind', () => {+      const {+        root,+        node: { codegenNode },+      } = parseWithForTransform(+        '<template v-for="item in items" :key="item.id"><slot v-bind="item.list"/></template>',+      )+      // the key must be passed as a separate renderSlot() argument instead of+      // being merged into the v-bind value (which may be an array)+      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"',+            { callee: NORMALIZE_PROPS },+            'undefined',+            'undefined',+            { content: `item.id` },+          ],+        },+      })+      expect(generate(root).code).toMatchSnapshot()+    })++    test('v-for on <slot/> w/ single v-bind', () => {+      const {+        root,+        node: { codegenNode },+      } = parseWithForTransform('<slot v-for="item in items" v-bind="item"/>')+      // no ref_for marker merged into the v-bind value of a slot outlet+      expect(+        assertSharedCodegen(codegenNode, false, true /* custom return */),+      ).toMatchObject({+        returns: {+          type: NodeTypes.JS_CALL_EXPRESSION,+          callee: RENDER_SLOT,+          arguments: [+            '$slots',+            '"default"',+            {+              callee: NORMALIZE_PROPS,+              arguments: [{ arguments: [{ content: `item` }] }],+            },+          ],+        },+      })+      expect(generate(root).code).toMatchSnapshot()+    })+     test('v-for on <slot/>', () => {       const {         root,packages/compiler-core/__tests__/transforms/vIf.spec.tsindex fe3aef714..87e31a785 100644@@ -26,6 +26,7 @@ import { import {   CREATE_COMMENT,   FRAGMENT,+  GUARD_REACTIVE_PROPS,   MERGE_PROPS,   NORMALIZE_PROPS,   RENDER_SLOT,@@ -112,6 +113,60 @@ describe('compiler: v-if', () => {       ).toBe(true)     }) +    test('v-if on <slot/> w/ single v-bind', () => {+      const {+        root,+        node: { codegenNode },+      } = parseWithIfTransform(`<slot v-if="ok" v-bind="items"></slot>`)+      // the branch key must not be merged into the slot props, otherwise an+      // array passed via v-bind would be turned into an object+      expect(codegenNode.consequent).toMatchObject({+        type: NodeTypes.JS_CALL_EXPRESSION,+        callee: RENDER_SLOT,+        arguments: [+          '$slots',+          '"default"',+          {+            type: NodeTypes.JS_CALL_EXPRESSION,+            callee: NORMALIZE_PROPS,+            arguments: [+              {+                type: NodeTypes.JS_CALL_EXPRESSION,+                callee: GUARD_REACTIVE_PROPS,+                arguments: [{ content: `items` }],+              },+            ],+          },+          'undefined',+          'undefined',+          { content: `0` },+        ],+      })+      expect(generate(root).code).toMatchSnapshot()+    })++    test('template v-if w/ single <slot/> child w/ single v-bind', () => {+      const {+        root,+        node: { codegenNode },+      } = parseWithIfTransform(+        `<template v-if="ok"><slot v-bind="items">fallback</slot></template>`,+      )+      expect(codegenNode.consequent).toMatchObject({+        type: NodeTypes.JS_CALL_EXPRESSION,+        callee: RENDER_SLOT,+        arguments: [+          '$slots',+          '"default"',+          { callee: NORMALIZE_PROPS },+          { type: NodeTypes.JS_FUNCTION_EXPRESSION },+          'undefined',+          { content: `0` },+        ],+      })+      expect(generate(root).code).toMatchSnapshot()+    })+     test('v-if + v-else', () => {       const { node } = parseWithIfTransform(`<div v-if="ok"/><p v-else/>`)       expect(node.type).toBe(NodeTypes.IF)packages/compiler-core/src/transforms/transformElement.tsindex 40f08d45b..4e61825c2 100644@@ -638,7 +638,11 @@ export function buildProps(             }              // #10696 in case a v-bind object contains ref-            pushRefVForMarker()+            // (skipped for <slot>: its v-bind value is passed to the slot+            // function as-is, e.g. an array must not be merged into an object)+            if (node.tagType !== ElementTypes.SLOT) {+              pushRefVForMarker()+            }             pushMergeArg()             mergeArgs.push(exp)           } else {packages/compiler-core/src/utils.tsindex aa426bbab..8d6959b80 100644@@ -445,6 +445,16 @@ export function injectProp(       props.properties.unshift(prop)     }     propsWithInjection = props+  } else if (node.type === NodeTypes.JS_CALL_EXPRESSION) {+    // <slot v-bind="exp"> - the value of a single v-bind is passed to the slot+    // function as-is (it may be a non-plain object such as an array), so+    // merging the key into it would change the slot props. Pass the key as a+    // separate renderSlot() argument instead.+    // renderSlot(slots, name, props, fallback, noSlotted, key)+    const args = node.arguments as CallExpression['arguments']+    while (args.length < 5) args.push(`undefined`)+    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..954b40028 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,13 +32,21 @@ export function renderSlot(   // the compiler and guaranteed to be a function returning an array   fallback?: () => VNodeArrayChildren,   noSlotted?: boolean,+  // branch key injected by the compiler (v-if / v-for) when the slot props come+  // from a single v-bind expression that must be passed to the slot as-is+  key?: PropertyKey, ): VNode {+  // a single `v-bind` on <slot> may evaluate to null / undefined+  if (props == null) props = {}   if (     currentRenderingInstance!.ce ||     (currentRenderingInstance!.parent &&       isAsyncWrapper(currentRenderingInstance!.parent) &&       currentRenderingInstance!.parent.ce)   ) {+    // props are set on an actual <slot> element here, so apply the branch key+    // to it (also copies props so the v-bind value is not mutated below)+    if (key !== undefined) 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@@ -80,6 +88,7 @@ export function renderSlot(     const validSlotContent = slot && ensureValidVNode(slot(props))     const slotKey =       props.key ||+      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..1d8fa90c7 100644@@ -915,6 +915,38 @@ describe('defineCustomElement', () => {         `<div><slot class="bar"></slot></div>`,       )     })++    // compiled `<slot v-if v-bind="obj">` passes the branch key separately+    test('render slot with compiler-injected branch key', async () => {+      const toggle = ref(true)+      const slotProps = { class: 'foo' }+      let slotVNode: any+      const E = defineCustomElement({+        render() {+          const fragment = toggle.value+            ? renderSlot(this.$slots, 'a', slotProps, undefined, undefined, 0)+            : renderSlot(this.$slots, 'b', slotProps, undefined, undefined, 1)+          slotVNode = (fragment.children as any[])[0]+          return [h('div', null, fragment)]+        },+      })+      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(+        `<div><slot class="foo" name="a"></slot></div>`,+      )+      expect(slotVNode.key).toBe(0)++      toggle.value = false+      await nextTick()+      expect(e.shadowRoot!.innerHTML).toBe(+        `<div><slot class="foo" name="b"></slot></div>`,+      )+      expect(slotVNode.key).toBe(1)+      // the bound object itself is passed to the outlet untouched+      expect(slotProps).toEqual({ class: 'foo' })+    })   })    describe('provide/inject', () => {packages/vue/__tests__/index.spec.tsindex 6eeff41dd..340fe0074 100644@@ -311,4 +311,111 @@ describe('compiler + runtime integration', () => {     app.mount(root)     expect(root.innerHTML).toBe('<div>60000000100000111</div>')   })++  it('should pass array slot props as-is when <slot> has v-if', async () => {+    const container = document.createElement('div')+    const show = ref(true)+    const items = ['a', 'b', 'c']+    const Child = {+      setup() {+        return { show, items }+      },+      template: `<slot v-if="show" v-bind="items" />`,+    }+    const App = {+      components: { Child },+      template: `<Child v-slot="props"><span v-for="i in props">{{ i }}</span>{{ Array.isArray(props) }}</Child>`,+    }+    createApp(App).mount(container)+    expect(container.innerHTML).toBe(+      `<span>a</span><span>b</span><span>c</span>true`,+    )++    show.value = false+    await nextTick()+    expect(container.innerHTML).toBe(`<!--v-if-->`)++    show.value = true+    await nextTick()+    expect(container.innerHTML).toBe(+      `<span>a</span><span>b</span><span>c</span>true`,+    )+  })++  it('should pass array slot props as-is for v-if / v-else <slot>', async () => {+    const container = document.createElement('div')+    const ok = ref(true)+    const Child = {+      setup() {+        return { ok }+      },+      template:+        `<slot v-if="ok" v-bind="['a', 'b']">fallback</slot>` ++        `<slot v-else name="other" v-bind="['c']" />`,+    }+    const App = {+      components: { Child },+      template:+        `<Child>` ++        `<template #default="p">{{ p }}</template>` ++        `<template #other="p">{{ p }}</template>` ++        `</Child>`,+    }+    createApp(App).mount(container)+    expect(container.innerHTML).toBe(`[\n  "a",\n  "b"\n]`)++    ok.value = false+    await nextTick()+    expect(container.innerHTML).toBe(`[\n  "c"\n]`)+  })++  it('should pass array slot props as-is for keyed <template v-for><slot>', () => {+    const container = document.createElement('div')+    const Child = {+      setup() {+        return {+          groups: [+            { id: 1, list: ['a', 'b'] },+            { id: 2, list: ['c'] },+          ],+        }+      },+      template: `<template v-for="g in groups" :key="g.id"><slot v-bind="g.list" /></template>`,+    }+    const App = {+      components: { Child },+      template: `<Child v-slot="props">{{ Array.isArray(props) }}-{{ props.length }};</Child>`,+    }+    createApp(App).mount(container)+    expect(container.innerHTML).toBe(`true-2;true-1;`)+  })++  it('should not crash when a conditional <slot> v-bind is nullish', () => {+    const container = document.createElement('div')+    const Child = {+      template: `<slot v-if="true" v-bind="null" />`,+    }+    const App = {+      components: { Child },+      template: `<Child v-slot="{ foo }">{{ foo === undefined }}</Child>`,+    }+    createApp(App).mount(container)+    expect(container.innerHTML).toBe(`true`)+  })++  it('should pass array slot props as-is for <slot v-for>', () => {+    const container = document.createElement('div')+    const Child = {+      setup() {+        return { lists: [['a', 'b'], ['c']] }+      },+      template: `<slot v-for="list in lists" v-bind="list" />`,+    }+    const App = {+      components: { Child },+      template: `<Child v-slot="props">{{ Array.isArray(props) }}-{{ props.length }};</Child>`,+    }+    createApp(App).mount(container)+    expect(container.innerHTML).toBe(`true-2;true-1;`)+  }) }) 
Merged fix · PR #15051+255 −11
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)