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

Two-way binding fails when bound to a sub-property when property is named component. #495

Closed
taylorzane opened this issue Apr 18, 2017 · 1 comment
Labels

Comments

@taylorzane
Copy link
Contributor

taylorzane commented Apr 18, 2017

Example

{{ component.name }} <!-- Simply to show that component.name fails to update. -->
<input bind:value="component.name"/>

<script>
export default {
  data () {
    return {
      component: {
        name: "world"
      }
    }
  }
}
</script>

<input>
REPL example

<select>
REPL example


Explanation

The initial render will work successfully, but when you attempt to change the value of component.name via the input, component.name does not update.

This seems to be caused by the $X_change_handler getSetter method using the name of the variable, without checking to see if it's been used before.

It seems like this would need multiple changes in order to get working.

Changes would need to be made to generators/dom/visitors/shared/binding/getSetter.js and utils/flattenReference.js (possibly others as I haven't fully investigated all locations) in order for name and keypath to be the correct.

It doesn't seem possible for this issue to be resolved by renaming the render_main_fragment argument component as any other name could, in theory, be used.

Workaround

Don't use component as a property name, currently using _component 😉

Rich-Harris added a commit that referenced this issue Apr 19, 2017
Rich-Harris added a commit that referenced this issue Apr 19, 2017
Rich-Harris added a commit that referenced this issue Apr 19, 2017
Deconflict variable names used in binding event handlers
@Rich-Harris
Copy link
Member

released 1.17 FYI — thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants