Fix #4097: error when View invalidated immediately

Bug introduced in 28c760e
This commit is contained in:
David Greenspan
2015-04-01 15:36:04 -07:00
committed by Slava Kim
parent 4689ee7dfa
commit 8b2c642df1
3 changed files with 31 additions and 1 deletions

View File

@@ -354,7 +354,9 @@ Blaze._materializeView = function (view, parentView, _workStack, _intoArray) {
// helpers in the DOM tree to be replaced might be scheduled
// to re-run before we have a chance to stop them.
Tracker.onInvalidate(function () {
domrange.destroyMembers();
if (domrange) {
domrange.destroyMembers();
}
});
}, undefined, 'materialize');

View File

@@ -32,6 +32,10 @@
{{/if}}
</template>
<template name="spacebars_template_test_bracketed_foo">
[{{foo}}]
</template>
<!-- -->

View File

@@ -2749,6 +2749,30 @@ Tinytest.add('spacebars-tests - template_tests - current view in event handler',
});
Tinytest.add('spacebars-tests - template_tests - helper invalidates self', function (test) {
var tmpl = Template.spacebars_template_test_bracketed_foo;
var count = new ReactiveVar(0);
tmpl.helpers({
// It's unusual for a helper to have side effects, but it's possible
// and people do it. Regression test for #4097.
foo: function () {
// Make count odd and return it.
var c = count.get();
if ((c % 2) === 0) {
count.set(c+1);
}
return c;
}
});
var div = renderToDiv(tmpl);
divRendersTo(test, div, '[1]');
count.set(2);
divRendersTo(test, div, '[3]');
});
Tinytest.add(
"spacebars-tests - template_tests - textarea attrs", function (test) {
var tmplNoContents = {