Skip to content

v-slot not working on component if mixing default and named slots - compiler error not helpful #6549

@noook

Description

@noook

Vue version

3.2

Link to minimal reproduction

https://stackblitz.com/edit/vue-ygckrr?file=src/App.vue

Steps to reproduce

  • Create a component with default slot, and named slots
  • On the Parent, use this component attaching v-slot on the component itself, and attach the method on a button.
  • The template won't compile

TabSelector

<template>
  <div>
    <slot :set-tab="setTab" />
  </div>
  <slot :name="modelvalue" />
</template>

App.vue

<script lang="ts" setup>
import { ref } from 'vue';
import TabSelector from './TabSelector.vue';
  
const currentTab = ref<'a' | 'b' | 'c'>('a');
</script>

<template>
  <TabSelector v-model="currentTab" v-slot="{ setTab }">
    <button @click="setTab('a')">
      Click on A
    </button>
    <button @click="setTab('b')">
      Click on B
    </button>
    <button @click="setTab('c')">
      Click on B
    </button>
    <template #a>
      This is A content
    </template>
    <template #b>
      This is A content
    </template>
    <template #c>
      This is A content
    </template>
  </TabSelector>
</template>

What is expected?

I shouldn't have to add an additional template tag to be able to use the scoped slot methods like this:

<template>
  <TabSelector v-model="currentTab">
    <template #default="{ setTab }"
      <div>
        <button @click="setTab('a')">Click on A</button>
        <button @click="setTab('b')">Click on B</button>
        <button @click="setTab('c')">Click on B</button>
      </div>
    </template>
    <template #a>A</template>
    <template #b>B</template>
    <template #c>C</template>
  </TabSelector>
</template>

What is actually happening?

It won't compile, and the message error is not clear.
Codegen node is missing for element/if/for node. Apply appropriate transforms first. on StackBlitz, and Uncaught TypeError: can't access property "name", AppComponent is undefined on https://sfc.vuejs.org

System Info

No response

Any additional comments?

I have reasons to believe this is normal behaviour, however it is not documented and it took me time to guess it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    🍰 p2-nice-to-havePriority 2: this is not breaking anything but nice to have it addressed.scope: compiler

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions