When a custom component is used as the root, attr can override explicitly set prop
Version
3.2.29
Reproduction link
Steps to reproduce
The above demo can show
What is expected?
1.attr should not be automatically passed from parent component to child component 2.Under the above premise, if attr and prop have the same name, attr should not overwrite prop 3.When a custom component is used as a root, it should behave as if it were wrapped in a div
What is actually happening?
1.attr(a) on Comp is automatically passed to CompChild, but not on CompA 2.attr (name) in comP is passed to props (name) of CompChild
I'll reopen this to re-evaluate one specific thing: attrs from parent overrwriting explicit props in the child, like this: Playground
That doesn't seem to be exactly desirable and would have worked differently in Vue 2 I_think_
one can also disable attributes inheritance
inheritAttrs:false
and manually pass attributes to the next child
// age is passthrough
// name is override
<CompChild name="Set by comp" v-bind:age=$attrs.age></CompChild>
I'll reopen this to re-evaluate one specific thing: attrs from parent overrwriting explicit props in the child
I don't think the fact it's is a prop or an attribute matters.
Since name
is merged from App.vue template into Comp.vue
, it makes sense for it to override the attribute/prop (going top down).
It's an edge-case, but a breaking change that we so far haven't documented.
App.vue > Comp.vue > Inner.vue
there is importance for name
being attribute in Comp.vue
attributes are expected to be applied to the root element,
which is then applied to <inner>
root element, overriding the explicit prop/attribute
documented https://v3.vuejs.org/guide/component-attrs.html#attribute-inheritance
props don't fall through for root elements.
In the context of Comp.vue
, name
is a non-prop attribute - Comp.vue doesn't have a prop named name
defined.
So the behavior matches the docs. it's just a subtle breaking change compared to Vue 2 that we so fare haven't documented.
I would say this is the more "correct" and expected behavior compared to Vue 2. name
is not declared by Comp
so it gets passed on to CompChild
, and because it's from higher-up, it has higher priority.
Also considering that changing this would technically constitute a breaking change in Vue 3, I think this is a wontfix.