Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toggling named template slots with v-if/v-else is not reliable #3976

Open
JamesBoon opened this issue Jun 18, 2021 · 4 comments
Open

toggling named template slots with v-if/v-else is not reliable #3976

JamesBoon opened this issue Jun 18, 2021 · 4 comments
Labels
has workaround A workaround has been found to avoid the problem scope: slots

Comments

@JamesBoon
Copy link

JamesBoon commented Jun 18, 2021

Version

3.1.1

Reproduction link

https://jsfiddle.net/4do76tf9/

Steps to reproduce

Just click "+1" in the jsfiddle demo.

What is expected?

Always the same letter should be shown.

What is actually happening?

The v-if content still shows up, even if the v-else should be used.


Noted in v3.0.11, confirmed in v3.1.1.

There is a workaround: just do not use v-if/v-else for named slots content. But it should at least throw a warning and/or be stated in the docs.

<!-- fails -->
<TestSlot>
  <template v-if="a" #content></template>
  <template v-else #content></template>
</TestSlot>
<!-- ok -->
<TestSlot>
  <template #content>
    <template v-if="a"></template>
    <template v-else></template>
  </template>
</TestSlot>

Update:
As @ShGKme pointed out in the comments, this works as expected in Vue 2.
Here is a quick demo of the Vue 2 behavior: https://jsfiddle.net/s7cpe1jk/

@posva
Copy link
Member

posva commented Jun 18, 2021

I would say the workaround is the preferred way to write it so you pass one single slot.

@posva posva added scope: slots has workaround A workaround has been found to avoid the problem labels Jun 18, 2021
@JamesBoon
Copy link
Author

I would say the workaround is the preferred way to write it so you pass one single slot.

This is absolutely ok, but the other way works somehow - and leads to this strange error shown in the jsfiddle.
Thus if there would be some kind of warning like "don't use v-if/v-else together with named slots" either in the console or the docs, it would already help a lot.

@ShGKme
Copy link

ShGKme commented Jun 18, 2021

In addition this works in Vue 2 and isn't mentioned in the Migration Guide.

@JamesBoon
Copy link
Author

@posva I've searched the tests a bit and found those for Vue 2: 'should work with v-if/v-else' and Vue 3: 'named slot with v-if + v-else-if + v-else'.
The fact that there are tests to cover the use of v-if/v-else together with named slots leaves the impression that the reported behavior is indeed a bug and not a missing feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has workaround A workaround has been found to avoid the problem scope: slots
Projects
None yet
Development

No branches or pull requests

3 participants