Skip to content

Databinding breaks after removing and reattaching an element to the DOM #311

Description

@ratatatata

Hi,

in the most recent version from git (date 2013-09-10), databinding seems to break if one removes an element from the DOM and reattaches it afterwards.

Tested in current versions of all evergreen browsers (especially chrome 30.0.1599.69 m).

Following fiddle demonstrates the problem: http://jsfiddle.net/Ysasn/1/

It contains a button that switches between two instances of an element that contains some basic databinding (the elements simply mirror the input of a textbox to a span; each button click removes the previously displayed instance from the DOM and (re)attaches the other instance of this databinding-test-element).
The databinding works fine for the first two clicks, when the my-binding-test elements get attached to the DOM the first time. BUT, after having clicked a third time (when the first my-binding-test instance gets reattached to the DOM) the data-binding is broken and doesn't propagate any changes anymore. Of course, this demo works fine, when reinstantiating the my-binding-test elements on each button click.

Don't hestitate to ask if you need any further information.

Regards,
André

Activity

  1. frankiefu commented on Oct 9, 2013

    @frankiefu
    Member

    Bindings are removed asynchronously when the element is removed from the document. To avoid that, call cancelUnbindAll() immediately after the element is removed.

    http://www.polymer-project.org/polymer.html#bindings

  2. sorvell commented on Oct 9, 2013

    @sorvell
    Contributor

    As Frankie noted, the intention is that you call cancelUnbindAll after removing sub1 or sub2. However, you'll currently need to also call CustomElements.takeRecords to ensure that the sub's leftViewCallback is processed first. Here's a working version:

    http://jsfiddle.net/d5dED/2/

    I've made another issue, linked above, to avoid the need to write polyfill aware code.

  3. sorvell commented on Oct 15, 2013

    @sorvell
    Contributor

    I'd like to point out that using conditional templates makes this type of construction very simple. Here's an example:

    http://jsfiddle.net/FbkvY/2/.

    Also see #312. The new preventDispose property can be used for this type of construction. Here's an updated fiddle: http://jsfiddle.net/WJ36P/1/.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions