Skip to content

Commit

Permalink
Fix #392 - Spark.isolate prints stack trace
Browse files Browse the repository at this point in the history
Isolates would print a stack trace upon re-render
if their DOM nodes had been manually removed from
the DOM without called Spark.finalize.
  • Loading branch information
dgreensp committed Jan 3, 2013
1 parent 3bada2a commit 577e1b6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/spark/spark.js
Expand Up @@ -543,6 +543,19 @@ var pathForRange = function (r) {
// `range` is a region of `document`. Modify it in-place so that it
// matches the result of Spark.render(htmlFunc), preserving landmarks.
Spark.renderToRange = function (range, htmlFunc) {
// `range` may be out-of-document and we don't check here.
// XXX should we?
//
// Explicit finalization of ranges (done within Spark or by a call to
// Spark.finalize) prevents us from being called in the first place.
// The newly rendered material will be checked to see if it's in the
// document by scheduleOnscreenSetUp's scheduled setup.
// However, if range is not valid, bail out now before running
// htmlFunc.
var startNode = range.firstNode();
if (! startNode || ! startNode.parentNode)
return;

var renderer = new Spark._Renderer();

// Call 'func' for each landmark in 'range'. Pass two arguments to
Expand Down
27 changes: 27 additions & 0 deletions packages/spark/spark_tests.js
Expand Up @@ -3821,4 +3821,31 @@ Tinytest.add("spark - legacy preserve names", function (test) {
Meteor.flush();
});

Tinytest.add("spark - update defunct range", function (test) {
// Test that Spark doesn't freak out if it tries to update
// a LiveRange on nodes that have been taken out of the document.
//
// See https://github.com/meteor/meteor/issues/392.

var R = ReactiveVar("foo");

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

test.equal(div.html(), "<p>foo</p>");
R.set("bar");
Meteor.flush();
test.equal(R.numListeners(), 1);
test.equal(div.html(), "<p>bar</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 577e1b6

Please sign in to comment.