Skip to content

Commit

Permalink
Further protect from stack traces on re-render
Browse files Browse the repository at this point in the history
  • Loading branch information
dgreensp committed Jan 3, 2013
1 parent 577e1b6 commit 5eae5ea
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/spark/spark.js
Expand Up @@ -606,8 +606,18 @@ Spark.renderToRange = function (range, htmlFunc) {
// find preservation roots that come from landmarks enclosing the // find preservation roots that come from landmarks enclosing the
// updated region // updated region
var walk = range; var walk = range;
while ((walk = findParentOfType(Spark._ANNOTATION_LANDMARK, walk))) while ((walk = walk.findParent())) {
pc.addRoot(walk.preserve, range, tempRange, walk.containerNode()); if (! walk.firstNode().parentNode)
// we're in a DOM island with a top-level range (not really
// allowed, but could happen if `range` is on nodes that
// manually removed.
// XXX check for this sooner; hard to reason about this function
// on a "malformed" liverange tree
break;

if (walk.type === Spark._ANNOTATION_LANDMARK, walk)
pc.addRoot(walk.preserve, range, tempRange, walk.containerNode());
}


pc.addRoot(Spark._globalPreserves, range, tempRange); pc.addRoot(Spark._globalPreserves, range, tempRange);


Expand Down
25 changes: 25 additions & 0 deletions packages/spark/spark_tests.js
Expand Up @@ -3846,6 +3846,31 @@ Tinytest.add("spark - update defunct range", function (test) {
Meteor.flush(); // should throw no errors Meteor.flush(); // should throw no errors
// will be 1 if our isolate func was run. // will be 1 if our isolate func was run.
test.equal(R.numListeners(), 0); test.equal(R.numListeners(), 0);

/////

R = ReactiveVar("foo");

div = OnscreenDiv(Spark.render(function () {
return "<p>" + Spark.setDataContext(
{},
"<span>" + Spark.isolate(function() {
return R.get();
}) + "</span>") + "</p>";
}));

test.equal(div.html(), "<p><span>foo</span></p>");
R.set("bar");
Meteor.flush();
test.equal(R.numListeners(), 1);
test.equal(div.html(), "<p><span>bar</span></p>");
test.equal(div.node().firstChild.nodeName, "P");
div.node().firstChild.innerHTML = '';
R.set("baz");
Meteor.flush(); // should throw no errors
// will be 1 if our isolate func was run.
test.equal(R.numListeners(), 0);

}); });


})(); })();

0 comments on commit 5eae5ea

Please sign in to comment.