vuejs / core

🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
https://vuejs.org/
MIT License
47.29k stars 8.27k forks source link

class prop do not append to component template root attribute in multiple template roots #1315

Closed Jackbennett closed 4 years ago

Jackbennett commented 4 years ago

Version

3.0.0-beta.14

Reproduction link

https://github.com/Jackbennett/vue3-dev-build/tree/vite

Steps to reproduce

Provided in the repo are screenshots for a quick view:

vite serve classes on the component used by app.vue are appened to the class property in the component vue.

vite build in production, the classes props are not appended to the component roots.

There is also a vue-cli branch reproducing the effect (with screenshots) to rule out the vite project. I'm not sure how vue changes into the production code to narrow much more down.

As you can see below look at the middle row background colours missing and the class attributes are removed in the build version.

What is expected?

vite serve output

What is actually happening?

vite build


v-if/v-else template root items work as expected, and I can manually bind the class prop as can be seen in expected.vue

yyx990803 commented 4 years ago

Not really a bug, because syntactically that’s three separate v-ifs that may or may not be true at the same time. So it’s considered a fragment root. Use v-else-if to avoid the ambiguity.

Jackbennett commented 4 years ago

That makes sense, Just coming back to it though because it works perfectly fine when running in dev. You run build and find the classes stripped out. No warnings are thrown, should it?

I have seen that fragmented root warning message but not doing this. I can see why v-else-if makes much better sense.