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

Regression: bindings don’t work with elements moved in the DOM #460

Closed
chasenlehara opened this issue Jun 1, 2018 · 1 comment
Closed
Assignees

Comments

@chasenlehara
Copy link
Member

As of can-stache-bindings 4.2.4 (with this change), bindings don’t work when an element is moved in the DOM like this:

export default Component.extend({
  tag: "my-app",
  view: "{{name}} <input on:input:value:bind='name' type='text' />",
  ViewModel: {
    name: "string",
    connectedCallback: function(element) {
      const wrapper = document.createElement("div");
      element.appendChild(wrapper);
      wrapper.appendChild(element.querySelector("input"));
    }
  }
});

Demo: https://codesandbox.io/s/m4ny5z8ovx

I’ve used on:input:value:bind just as an example, but this bug is not specific to that kind of binding.

@justinbmeyer
Copy link
Contributor

This sort of manipulation of the DOM isn't really supported and is likely to cause trouble. I'm not sure this is technically a regression.

The fix is to have another level of "tearItAllDown" ... one for the nodelist to call, where it doesn't matter if the DOM is in the page or not. Another one for the DOM Mutation callback where it checks if the node is still in the page.

@chasenlehara chasenlehara self-assigned this Jun 1, 2018
chasenlehara added a commit that referenced this issue Jun 1, 2018
When can-dom-mutate reports that a node has been removed, we first check whether the node is still in the document before tearing down its bindings.

Fixes #460
chasenlehara added a commit that referenced this issue Jun 1, 2018
When can-dom-mutate reports that a node has been removed, we first check whether the node is still in the document before tearing down its bindings.

Fixes #460
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

2 participants