Blaze.render() & Blaze.remove() renders template twice!?


#1

Hi!

I’m implementing a pop-up which sits in the highest parent template. I call a Blaze.render() from a child template to trigger the pop-up. I can close the pop-up and ‘clean-up’ afterwards by calling Blaze.remove(). However, when I re-trigger the pop-up again it shows it twice!
After Blaze.remove() the template is gone, but under the hood it somehow still must be stored and hence duplicated upon re-render? Here’s the relevant code:

// in pop-up template
Template.generalPopUp.onCreated(function() {
	console.log("generalPopUp BORRRN!!!")
})
Template.generalPopUp.onDestroyed(function() {
	console.log("generalPopUp KILLED!!!")
})
Template.generalPopUp.events({
	'click #close-popup': function(e, t) {
		Blaze.remove(Blaze.getView($("#pop-up-wrapper")[0]))
	}
})


// in child template upon 'click .btn'
Blaze.render(Template.generalPopUp, $('#pop-up-wrapper')[0]);

#2

I solved it! But I think it is a bug. Reading the source code, Blaze.remove() says it expects a Blaze renderedView, which is either from getView(‘DOM element’), Template.instance().view or the view object Blaze.render() returns.
So even though the DOM element selection should work, it fails to clean-up properly. Using Template.instance().view worked for me.