From 5862ec036336be1e7d341eec88742fc729cb452b Mon Sep 17 00:00:00 2001 From: Avital Oliver Date: Mon, 26 Jan 2015 15:52:44 -0800 Subject: [PATCH] Make `Template.instance()` correct in `this.autorun()` in templates A previous change decoupled "current view" from "current template instance". The code made sure to preserve "current view" explicitly within `this.autorun`, but now we need to do the same for "current template instance" --- packages/blaze/view.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/blaze/view.js b/packages/blaze/view.js index 1f5ab481e0..ce40478d0c 100644 --- a/packages/blaze/view.js +++ b/packages/blaze/view.js @@ -174,9 +174,13 @@ Blaze.View.prototype.autorun = function (f, _inViewScope) { throw new Error("Can't call View#autorun from a Tracker Computation; try calling it from the created or rendered callback"); } + var templateInstanceFunc = Blaze.Template._currentTemplateInstanceFunc; + var c = Tracker.autorun(function viewAutorun(c) { return Blaze._withCurrentView(_inViewScope || self, function () { - return f.call(self, c); + return Blaze.Template._withTemplateInstanceFunc(templateInstanceFunc, function () { + return f.call(self, c); + }); }); }); self.onViewDestroyed(function () { c.stop(); });