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

New (2.6 ) slot syntax results in slots not added to vm.$slots, breaking existing render functions #9421

Closed

Comments

@K900
Copy link

K900 commented Feb 4, 2019

Version

2.6.1

Reproduction link

https://jsfiddle.net/3kpf9u54/4/

Steps to reproduce

  1. Observe the contents of the <template> displayed
  2. Change the code from <template slot="content"> to <template #content> or <template v-slot:content> and observe the contents stop being displayed
  3. Change the render function code from this.$slots.content to this.$scopedSlots.content() and observe the contents be displayed again

What is expected?

Contents are displayed all the time; old render functions don't break when used with new syntax

What is actually happening?

New syntax forces slots into being scoped, breaking existing render functions


I'm actually not sure if this is intentional or not, but it breaks Vuetify, and probably other things too. Assuming this is intentional, it makes writing functional components more difficult, as you have to either:

  1. check both this.$slots (for Vue pre-2.6) and this.$scopedSlots (for Vue post-2.6)
  2. only check this.$scopedSlots and ask Vue pre-2.6 users to add slot-scope everywhere so all slots become scoped
  3. only check this.$slots and ask Vue post-2.6 users to use the legacy syntax
@KaelWD
Copy link
Contributor

KaelWD commented Feb 5, 2019

but it breaks Vuetify

We were going to release a new minor version with $slots replaced by $scopedSlots, this change breaks v-slot (and slot-scope) use with dialog and menu activators

@KaelWD
Copy link
Contributor

KaelWD commented Feb 5, 2019

The plan was 3 for vuetify 1.4/1.5, then release vuetify 1.6 with a minimum vue version of 2.6 so old templates would still work.

Simple codepen demonstrating the problem: https://codepen.io/anon/pen/xMLreR?editors=1010
2.6.0: https://codepen.io/anon/pen/xMLreR?editors=1010

@KaelWD
Copy link
Contributor

KaelWD commented Feb 5, 2019

So I found this, which I guess works for those edge cases: https://codepen.io/anon/pen/BMddNv?editors=1010

KaelWD added a commit to vuetifyjs/vuetify that referenced this issue Feb 5, 2019
@K900
Copy link
Author

K900 commented Feb 5, 2019

@KaelWD This is now fixed in upstream Vue, and it seems your change actually makes things worse now :(

@yyx990803
Copy link
Member

Note: this has been reverted (exposing scoped slots on $slots) as it is technically a breaking change.

The original issue, however, is not since the new syntax is opt-in. Users can keep using the old syntax while waiting for libraries to properly migrate to use this.$scopedSlots in all cases.

@K900
Copy link
Author

K900 commented Feb 6, 2019

This is definitely an interesting problem, and one I don't really see a good solution for... I guess there's not much we can do now that this behavior is stable, except wait for the ecosystem to catch up :(

@yyx990803
Copy link
Member

In 0e8560d I've made it so that only slots using the new v-slot syntax without scope are exposed on this.$slots. This should ensure intended behavior without affecting existing usage of legacy slots.

@joelpro2
Copy link

joelpro2 commented Apr 23, 2019

i made a simple test and v-slot still dont add the slots in $slots
fiddle
My bad, i was using vue 2.6.0, its corrected in 2.6.10

Lostlover pushed a commit to Lostlover/vue that referenced this issue Dec 10, 2019
Lostlover pushed a commit to Lostlover/vue that referenced this issue Dec 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment