Permalink
Browse files

Further protect from stack traces on re-render

  • Loading branch information...
1 parent 577e1b6 commit 5eae5eae4c18183ed91249c13a27796dd061ec89 @dgreensp dgreensp committed Jan 3, 2013
Showing with 37 additions and 2 deletions.
  1. +12 −2 packages/spark/spark.js
  2. +25 −0 packages/spark/spark_tests.js
View
@@ -606,8 +606,18 @@ Spark.renderToRange = function (range, htmlFunc) {
// find preservation roots that come from landmarks enclosing the
// updated region
var walk = range;
- while ((walk = findParentOfType(Spark._ANNOTATION_LANDMARK, walk)))
- pc.addRoot(walk.preserve, range, tempRange, walk.containerNode());
+ while ((walk = walk.findParent())) {
+ 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);
@@ -3846,6 +3846,31 @@ Tinytest.add("spark - update defunct range", function (test) {
Meteor.flush(); // should throw no errors
// will be 1 if our isolate func was run.
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.