Skip to content

Scoped slot transforms array argument if rendered conditionally #15048

Closed

Description

@Truevoly

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

Image

System Info

Any additional comments?

key attribute is generated by the compiler for the slot rendered with v-if.

Image

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.

Activity

  1. DaZuiZui commented on Jul 7, 2026

    @DaZuiZui
    Contributor

    I took a look at this and the root cause seems to be that the compiler-injected branch key for the conditional slot outlet is leaking into the scoped slot props.

    For this template, the conditional slot is compiled roughly as:

    _renderSlot(, "default", _normalizeProps(_mergeProps({ key: 0 }, items)))

    The injected key is needed by v-if/branch codegen so renderSlot can produce a stable fragment key. However, renderSlot currently uses the same props object both as metadata for the rendered slot fragment and as the object passed to the user slot function. When v-bind receives an array, mergeProps treats it like an object and enumerates its indexes, so the parent slot receives an object like { 0: 'item1', 1: 'item2', 2: 'item3', key: 0 } instead of the original array-like value.

    So this is not the source array being mutated; it is the internal branch key being merged into the slot props object and exposed to userland. A fix probably needs to distinguish compiler-injected slot outlet keys from user-provided slot props, so renderSlot can still use the key for fragment identity without passing that internal key through to the scoped slot.

    I'll work on this.

  2. added
    🔨 p3-minor-bug
    on Jul 8, 2026
  3. added a commit that references this issue on Jul 16, 2026
    20c9d26
  4. locked and limited conversation to collaborators on Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    🔨 p3-minor-bugscope: compiler

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions