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

Items pushed on lists don't get removed from the DOM in some cases #605

Closed
daffl opened this issue Dec 10, 2013 · 3 comments · Fixed by #615
Closed

Items pushed on lists don't get removed from the DOM in some cases #605

daffl opened this issue Dec 10, 2013 · 3 comments · Fixed by #615
Assignees
Labels
Milestone

Comments

@daffl
Copy link
Contributor

daffl commented Dec 10, 2013

In certain cases elements pushed to a list that is rendered with each stay in the DOM even if the parent element has been removed (interestingly enough all wrapping DOM will be gone as well). Using a template like:

<div>
{{#data}}
    <p>This is the item:</p>
    {{#item}}
        {{#each subitems}}
            <div class="item">
                {{test}}
            </div>
        {{/each}}
    {{/item}}
{{/data}}
</div>

And this component:

can.Component.extend({
    tag: 'editor',
    template: can.view('editor'),
    scope: {
        data: {
            item: {
                name: "My Name",
                subitems: [{
                    test: 'first'
                }]
            }
        }
    },
    events: {
        inserted: function() {
            var scope = this.scope;
            scope.attr('data.item.subitems').push({
                test: 'Pushed item'
            });
            setTimeout(function() {
                scope.attr('data').removeAttr('item');
            }, 3000);
        }
    }
});

$('#container').html(can.view('tpl', {}));

The fragment for the dynamically added Pushed item will remain in the DOM after calling .removeAttr('item').

Fiddle demonstrating the issue: http://jsfiddle.net/Cjsqz/1/

@justinbmeyer
Copy link
Contributor

This means the items added are not properly registering themselves in node_list.

@matthewp
Copy link
Contributor

Hey @justinbmeyer I took a look at this bug a little bit and the item does call nodeLists.register, although I'm not sure what that actually achieves as far as node removal. The first item gets removed through live.html's makeAndPut function. Should both items be removed at that time?

@justinbmeyer
Copy link
Contributor

Closing because of pull request #614

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

Successfully merging a pull request may close this issue.

3 participants