-
-
Notifications
You must be signed in to change notification settings - Fork 675
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
vue/no-multiple-template-root
false negative with comment
#2316
Comments
vue/no-multiple-template-root
doesn't throw an error when it shouldvue/no-multiple-template-root
false negative with comment
I see that you are using Vue 3 in your reproduction repository, and manually enable the So do I understand correctly that this is a convention that you would like to enforce? I guess that setting the |
@FloEdelmann The rule itself is not that much of an edge case in a Vue 3 environment, considering Nuxt also advises you to have a single root for pages / layouts if you want any sort of transitions. Yes, |
Good to know; would you fancy opening a PR to add this (with a link to the relevant Nuxt docs) to the rule docs?
We don't know in ESLint whether the |
These are the corresponding Nuxt docs (https://nuxt.com/docs/guide/directory-structure/pages#usage): ![]() |
When you have a comment in the root of your template in vue 3, using $el will point to the first text comment instead of the actual DOM element. This can cause unwanted bugs, certainly because the comments are only stripped in production. <template>
<!-- Oops -->
<div>
Hello world
</div>
</template>
<script lang="ts">
import { defineComponent } from "vue";
export default defineComponent({
mounted() {
console.log(this.$el); // logs `#text ""`
}
});
</script> |
I guess that we can add an option to the {
"vue/no-multiple-template-root": ["error", {
disallowComments: true // default: false
}]
} @SimonBackx That sounds like a bug in Vue itself though, don't you think? Did you report it there already? |
Checklist
Tell us about your environment
Please show your full configuration:
What did you do?
IMPORTANT CONTEXT: the Vue compiler has
comments: true
turned on (as a necessity). What this means is that the root template in this mode actually has multiple roots, including a blank text node, a comment node, and the div. I want to prevent developers from making this mistake, so I need a way to flag this as an error.What did you expect to happen?
I expected an ESLint error when there are multiple possible roots.
What actually happened?
There is no error, hence no output.
Repository to reproduce this issue
https://stackblitz.com/edit/vitejs-vite-mhdbqk?file=src%2FApp.vue
The text was updated successfully, but these errors were encountered: