Extraneous non-props attributes (class) were passed to component but could not be automatically inherited because component renders fragment or text root nodes.
Link to minimal reproduction
Steps to reproduce
Create a component with conditional rendering, each condition already has a single root.
<template>
<template v-if="to">
<RouterLink v-if="isRoute" :to="href" v-bind="commonAttrs" :class="classList">
<slot />
</RouterLink>
<a v-else :href="href" v-bind="commonAttrs" :class="classList">
<slot />
</a>
</template>
<div v-else v-bind="commonAttrs" :class="classList">
<slot />
</div>
</template>
<script lang="ts" setup>
import { computed, inject, useAttrs } from 'vue'
import type { RouteLocationRaw } from 'vue-router'
import useLink from './useLink.ts'
interface Props {
to?: RouteLocationRaw
}
const props = defineProps<Props>()
const emit = defineEmits(['click'])
const attrs = useAttrs()
const { href, isRoute } = useLink(props, attrs)
const classList = computed(() => {
return ['e-menu-item']
})
const onClick = () => {
console.log('click')
}
const onMouseover = () => {
console.log('mouseover')
}
const commonAttrs = {
...attrs,
onClick,
onMouseover,
}
</script>
when I use this component and pass a class attribute it outputs the following warning.
<MenuItem class="menu-item" to="/user/settings">
Profile
</MenuItem>
[Vue warn]: Extraneous non-props attributes (class) were passed to component but could not be automatically inherited because component renders fragment or text root nodes.
What is expected?
Should not show this warning as the component is rendering with a single root.
What is actually happening?
This is the rendered HTML with the warning [Vue warn]: Extraneous non-props attributes (class) were passed to component but could not be automatically inherited because component renders fragment or text root nodes.
<a href="/user/settings" class="menu-item e-menu-item"><!--[--> Profile <!--]--></a>
System Info
System:
OS: macOS 10.15.7
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Memory: 934.50 MB / 16.00 GB
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 16.8.0 - /usr/local/bin/node
Yarn: 1.22.17 - ~/.yarn/bin/yarn
npm: 7.21.0 - /usr/local/bin/npm
Browsers:
Chrome: 101.0.4951.64
Edge: 101.0.1210.47
Firefox: 100.0
Safari: 15.4
### Any additional comments?
_No response_
It's a bit of a question how deep the compiler should follow this rabbit hole of nested v-if
fragments, but it should be doable. We'll rarely have this more than 3 levels deep.