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

Default slot does not render template without v-slot directive #2110

Closed
doman412 opened this issue Sep 14, 2020 · 3 comments
Closed

Default slot does not render template without v-slot directive #2110

doman412 opened this issue Sep 14, 2020 · 3 comments

Comments

@doman412
Copy link

Version

3.0.0-rc.10

Reproduction link

https://jsfiddle.net/doman/k1w2L9vj/14/

Steps to reproduce

Pass a template as the default slot without using v-slot directive.

i.e.

<my-comp>
  <template>
    <p>render me</p>
  </template>
</my-comp>

What is expected?

The template's contents should be inserted into the DOM and rendered into the default slot.

What is actually happening?

The template and its contents are being inserted into the DOM but the template content is not rendered.


I have a component that passes data into the default slot and and I use v-slot to access that data. But in one instance when I didn't need the data, I left the directive off and noticed my contents were not being rendered properly. I think under normal circumstances you just add #default to the tag but it still seems like a bug.

@HcySunYang
Copy link
Member

In V3, the <template> without the v-if/else/else-if/for/slot directives is treated as a HTML Content Template (<template>) element

@posva
Copy link
Member

posva commented Sep 14, 2020

I think it would make sense to only treat it as an template tag if it's used alongside v-pre. In Vue 2, the behavior is not completely consistent:

  • Using one single template:
     <template v-pre>
       Hello {{''}}
       </template>
    still outputs Hello {{''}}
  • While using two templates:
       <template v-pre>
         <template>Hello 4</template>
       </template>
    renders two document fragments (https://jsfiddle.net/795man4w/)

There is also this issue in Vue 2 vuejs/vue#10717

@yyx990803
Copy link
Member

I guess the question is why would one ever use <template> without a directive like that. It is indeed a different behavior from v2 but I don't think the v2 behavior has any practical use cases (while at the same time blocking the ability to render a native <template> tag). For that I would consider this an intended change (minor breakage) and we should document it in the migration guide.

@github-actions github-actions bot locked and limited conversation to collaborators Nov 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants