Fix nested autoruns in Blaze rendering

Should address bugs where helpers fire more than expected, and also prevent wasted re-rendering of templates that are being destroyed anyway.

See: https://github.com/EventedMind/iron-router/issues/478
This commit is contained in:
David Greenspan
2014-03-10 14:31:12 -07:00
parent ac58f6d8b7
commit f97708bf19

View File

@@ -243,13 +243,20 @@ var updateAttributes = function(elem, newAttrs, handlers) {
UI.render = function (kind, parentComponent) {
if (kind.isInited)
throw new Error("Can't render component instance, only component kind");
var inst = kind.instantiate(parentComponent);
var content = (inst.render && inst.render());
var inst, content, range;
var range = new UI.DomRange;
inst.dom = range;
range.component = inst;
Deps.nonreactive(function () {
inst = kind.instantiate(parentComponent);
content = (inst.render && inst.render());
range = new UI.DomRange;
inst.dom = range;
range.component = inst;
});
materialize(content, range, null, inst);
@@ -346,9 +353,7 @@ var materialize = function (node, parent, before, parentComponent) {
if (! c.firstRun)
range.removeAll();
Deps.nonreactive(function () {
materialize(content, range, null, parentComponent);
});
materialize(content, range, null, parentComponent);
}
});
range.removed = function () {