Skip to content
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

camelCased props bound through an object take precedence over a kebab cased specific prop #9641

Closed
thedamon opened this issue Mar 6, 2019 · 3 comments

Comments

@thedamon
Copy link

thedamon commented Mar 6, 2019

Version

2.6.8

Reproduction link

https://codesandbox.io/s/54v49n1nzn

Steps to reproduce

The repro shows the issue directly.

<Child
      v-bind="{
        appleColor: 'objective red',
        bird: 'objective sparrow'
      }"
      :apple-color="`proper red`"
      :bird="`proper sparrow`"
    />

What is expected?

I wanted to know what takes precedence when something is bound using v-bind={} vs set explicitly as a prop. I would expect this to always be one or the other, or to be resolved in order of declaration as when merging objects in JS ({...boundProps, specificProp })

What is actually happening?

The precedence is determined based on whether a prop has multiple words. duplicate keys are set by the object when they are declared in dash-case, and set by the prop/attribute if they are camelCase or a single word.


This can be made 'consistent' by declaring multiword props using camelcase, but that's against the recommendations in the styleguide which suggest using dash case for multiword props inside templates: https://vuejs.org/v2/style-guide/#Prop-name-casing-strongly-recommended.

I ran into this when an undefined value bound to a parent was overriding the same value explicitly set in the child, but it wasn't happening consistently depending on what the names of the props were.

@posva posva added the bug label Mar 6, 2019
@posva
Copy link
Member

posva commented Mar 6, 2019

Indeed, seems that the camelCase version always takes precedence.
It's fixed if using a camelCased prop: appleColor

The expected behaviour would be the specific apple-color to always take precedence regardless of the order of HTML attributes

@posva posva changed the title Inconsistent duplicate key behaviour in v-bind object and prop/attrs camelCased props bound through an object take precedence over a kebab cased specific prop Mar 6, 2019
@thedamon
Copy link
Author

thedamon commented Mar 7, 2019

I was actually in the midst of submitting a PR to the API docs in the v-bind section to say what takes precedence (since I think it makes sense to mention that) when I did a test and realized that there's not a simple answer.

@posva
Copy link
Member

posva commented Mar 7, 2019

I forgot to say but this rings a bell but I couldn't find the issue/pr related but I'm pretty sure there was something already opened

@Justineo Justineo added the has PR label Mar 8, 2019
Justineo added a commit to Justineo/vue that referenced this issue Mar 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants