Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix #392 - Spark.isolate prints stack trace

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...
commit 577e1b6b12a8c47673aa3de53cb98bf377bd58f6 1 parent 3bada2a
@dgreensp dgreensp authored
Showing with 40 additions and 0 deletions.
  1. +13 −0 packages/spark/spark.js
  2. +27 −0 packages/spark/spark_tests.js
View
13 packages/spark/spark.js
@@ -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
View
27 packages/spark/spark_tests.js
@@ -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);
+});
+
})();
Please sign in to comment.
Something went wrong with that request. Please try again.