sproutcore/sproutcore20 — Issue #233: Appending and removing a view in a single runloop
Author: manko
Created: 2011-12-08 22:18:22+00:00
State: open

If you append and remove a view in a single runloop, the view ends up shown in DOM. I've written two test cases to demonstrate the problem (could go to sproutcore-views/tests/views/view/remove_test.js):

```javascript
test("the DOM element is gone after doing append and remove in two separate runloops", function() {
var view = SC.View.create();
SC.run(function() {
view.append();
});
SC.run(function() {
view.remove();
});

var viewElem = SC.$('#'+get(view, 'elementId'));
ok(viewElem.length === 0, "view's element doesn't exist in DOM");
});

test("the DOM element is gone after doing append and remove in a single runloop", function() {
var view = SC.View.create();
SC.run(function() {
view.append();
view.remove();
});

var viewElem = SC.$('#'+get(view, 'elementId'));
ok(viewElem.length === 0, "view's element doesn't exist in DOM");
});
```

The first test case passes, the second one fails. In practice we see this happening with SC.CollectionView, sometimes it shows the empty view *and* a list of items (happens at least when content is a datastore-backed array).

Unfortunately no fix yet... I can try to fix it if somebody could provide some tips on what would be the most sensible approach.