-
-
Notifications
You must be signed in to change notification settings - Fork 9k
Open
Labels
Description
Version
3.2.31
Reproduction link
vue-next-template-explorer.netlify.app
Steps to reproduce
Look at the AST for the SFC. In the dev console, you can see the component has only one child.

The workaround example (from below) has the part that is missing. branches is present for conditional rendering

What is expected?
Both named-slots are registered in the AST.
What is actually happening?
Only one of the conditional templates with named slots is registered in the AST. The second is not.
Reference: vuejs/language-tools#1150
Workaround: not put a condition on template of named slot but instead make the content conditional
SFC that generates bad AST
<script
setup
lang="ts"
>
import { ref } from 'vue';
import ComponentWithSlots from '@/src/foobar';
const aVariableThatExists = ref(true);
</script>
<template>
<ComponentWithSlots>
<template
#content
v-if="aVariableThatExists"
>
<div>{{ aVariableThatExists }}</div>
</template>
<template
#content
v-else
>
<div>{{ thisVariableDoesNotExist }}</div>
<div>{{ thisShouldBeUnderlinedInRed }}</div>
</template>
</ComponentWithSlots>
</template>Workaround SFC
Move the conditional logic into the children of a single slotted template. Define an extra set of template tags that the conditional logic can live on:
<script
setup
lang="ts"
>
import { ref } from 'vue';
import ComponentWithSlots from '@/src/foobar';
const aVariableThatExists = ref(true);
</script>
<template>
<ComponentWithSlots>
<template
#content
>
<template v-if="aVariableThatExists">
<div>{{ aVariableThatExists }}</div>
</template>
<template v-else>
<div>{{ thisVariableDoesNotExist }}</div>
</template>
</template>
</ComponentWithSlots>
</template>