Skip to content

Conditionally rendered slots are ending up last in the $slots object #14425

@andreww2012

Description

@andreww2012

Vue version

v3.6.0-beta.5

Link to minimal reproduction

https://play.vuejs.org/#eNp9U8Fu2zAM/RVOG5AEaO2h3XbonGBr0QHdYR26HQWsjkOnSmzJkGQ3q+F/L2VHiWOkuVHke08U+VSz70URVCWyKxaZRIvCgkFbFjMuRV4obaEGjSk0kGqVw4igo13pRuXFNh+E7uCURl+55DJR0pDUk3q+jjVMncbY6hInVI3C7ia6gw4W8yKLLdIJIFqIqg0onJfWKgnfkkwk6ylne7F325Cz2QPKBWp4nMf6EUymbBR2vE4u9HqRa88r+yvhPdGgOhfpXp40KRmFB20NORee5J7UMS5OUVKlZj+UOq36QjIvA0jUjpXCgzw7Y9bQhFOxDFZGSVpe7dCcJYQWGer7wgraAGdX0FZcLc4y9fyzzbm2z3w+ecJkfSS/MhuX4+y3RoO6oofuajbWS7Rd+fbPL9xQvCvmalFmhD5RfECjstL12MGuS7mgtnu4ttu71mdCLv+a241Fafyj2rkTsmnxnJHv3KDeevq+3cvgU8vjsqEpes8O3Q9ZLJduvSTT/wkkclNqjdLekb1jmeDBx+g5X/j69AhpPDn9CYpZXcP9fIWJDdb434w/OGebCTQN+DgKOzsfAQd99PbwNtx32mcNch15aMF/FWq3EBreZfAl+Hg+RxsHn1nzCmENddI=

Steps to reproduce

Slots accessed via $slots normally preserve their order from the template:

<script setup>
import Comp from './Comp.vue';
</script>

<template>
  <Comp>
    <template #foo>foo</template>
    <template #bar>bar</template>
  </Comp>
</template>

<!-- Comp.vue -->
<template>
  <div>{{ Object.keys($slots) }}</div>
</template>

Rendered as:

[ "foo", "bar" ]

... unless they have v-if directive, even if with a constant condition. Such slots are always ending up last, and placed in the order they're rendered:

<script setup>
import Comp from './Comp.vue';
</script>

<template>
  <Comp>
    <template #foo>foo</template>
    <template #baz v-if="true">baz</template>
    <template #bar>bar</template>
  </Comp>
</template>

<!-- Comp.vue -->
<template>
  <div>{{ Object.keys($slots) }}</div>
</template>

Rendered as:

[ "foo", "bar", "baz" ]

What is expected?

I expect $slots to provide the passed slots in order reflecting their position in the template, regardless of presense of v-if directive.

What is actually happening?

Described in the repro.

System Info

Any additional comments?

I have a component that renders arbitrary number of slots, and it's crucial for preserve their order.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions