-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
Attribute Inheritance broken when comment in template root #9591
Comments
class、style、inheritAttrs are only effective when there is a single root element in the template. https://vuejs.org/guide/components/attrs.html#attribute-inheritance |
Comments should be ignored in that consideration, though. They are in dev, which is making this a bug. |
I think this is a playground bug. Vue's compiler will delete the comment node in the production mode build, but in the playground, it is a fragment. |
The behavior is inconsistent between the development and production env, and the reason is that commented-out nodes have not removed in the production env. |
Also encountering this issue in Vue3 when migrating a Vue2 app which uses conditional (singular) roots, where there are template comments above each root option. The comments seem to be interpreted as fragments, and thus throwing the following warning about the
Without removing root-level template comments, or adding Here is a reproduction to the issue: If you toggle between prod/dev modes and recent Vue versions v3.4 and v3.3, you will observe inconsistencies with how the Whilst I see there is a potential fix associated with the SFC playground (#9594), in practice I am seeing this issue on locally served dev builds (through vite) using v3.3.x. I would not expect the behaviour of attribute inheritance to differ between environments based on comments in the template - they should be ignored and not interpreted as fragments. Edit: I note that for local dev builds using later revisions of v3.4 this seems to be now fixed, but this open issue is not linked to the specific change in the core that fixed it, so the behaviour might have been fixed by coincidence. Edit 2: I've identified this behaviour was specifically fixed in v3.4.11, so can be considered a duplicate of #5203, anybody else experiencing this should upgrade to v3.4 (v.3.4.15+) now v3.4 appears more stable. |
Comments are not necessarily removed in production builds, it's controlled by a setting: https://vuejs.org/api/application.html#app-config-compileroptions-comments. I've just tested using 3.4.23 and Vite. I can reproduce the problem described here if I set |
I do not think it is a playground bug, only. We are seeing this issue in production only, although we are using the default setup of the VueLoader which – according to the documentation – defines Even when I explicitly define new VueLoaderPlugin({
compilerOptions: {
comments: false
}
}), Update: Aha, looks like this is a known VueLoader issue – sorry for checking the vuejs/vue-loader issues to late… |
@p3k |
@edison1105 Please see the Update I added to my previous post. Looks like there is a similar VueLoader issue. |
@p3k {
test: /\.vue$/,
loader: 'vue-loader',
options: {
compilerOptions: {
comments: false
},
},
}, |
Aha, thanks for the correction @edison1105 – this indeed removes the comments. In the meantime I understand our issue is related to fallthrough attributes and multiple root nodes:
(Not seeing the warning, though.) I also understand a comment is regarded as a node in the DOM tree – at the same time wondering whether it is a bit confusing it is treated as such because fallthrough attributes cannot be applied to it, anyway 🤔 |
Vue version
3.3.8
Link to minimal reproduction
https://play.vuejs.org/#eNp9UsFOwzAM/RUvl4K0rkK7bd0kQJOAAyCYxCWX0XlbRppESTqGqv47Tkq7HYBb/N6z/WynZtfGjA4VsgnLXWGF8eDQV2bOlSiNth5qsLiBBjZWl5CQNOmpW12aH3yUhSBUSqZccVVo5TyUbguzkH+R3KGUGt60letBcslVnrXtqBEFHksjVx4pAsh3V/O6jslNk2cURVQoU3k4pKVeo5xxRjxnLRWNOP8lkfBCS20n8C4rnHIGGUnyrG/Ahsw7crcR29HeaUWD16FGyCuNkGifjBfknrMJRCZwKzL/+RAxbyscdnixw+LjF3zvjgHj7NmiQ3tAznrOr+wWfUsvXh/xSO+epOEqSep/yBd0WlbBYyu7qdSabJ/potv7eCOhtku3OHpUrhsqGA3KJuo5o5uF/f01+snueDSOeVw1tMXu3uHnnM5nadmDNAVaZonKQ5q22Foc4gNgKTwNGLCsA8/P03wDu53amQ==
Steps to reproduce
Create a Component with a comment in template root
Use the component.
What is expected?
What is actually happening?
System Info
No response
Any additional comments?
No response
The text was updated successfully, but these errors were encountered: