Blaze.remove() isn't working

I’m trying to use Blaze.remove() but it’s not working when I store the returned value of renderWithData() as a variable to use to remove the view later.

I’m displaying a list of function names with the code below:

{{#each functionName in functionList}}
    <div class="{{functionName}}" id="{{functionName}}">

I have a template event function (below). When I render the template with data, I add the returned view to the renderedViews object. The setTimeout function afterwards can remove the view no problem. When I click the div again and it finds that the view already exists by checking the renderedViews object, it is unable to remove the view. No errors are thrown, nothing happens.

'click div': function (event, instance) {
		var functionName = event.currentTarget.className;
		console.log('event: ' + functionName);
		// If the view already exists when the title is clicked, remove it from the DOM
		if(renderedViews.hasOwnProperty(functionName)) {
		// Render a view and save the view for later so it can be removed
		let renderedView = Blaze.renderWithData(
			Template.content, // The template being rendered
			data(functionName), // The function called for data
			event.currentTarget // The DOM node where the template is getting insterted
		// Store the rendered view in renderedViews object with a property name of functionName
		renderedViews[functionName] = renderedView;
		setTimeout(function() {
		}, 5000);

Am I doing something wrong or is this a bug? Thanks for the help.

Blaze.remove does work, we use it all the time.

Maybe you have intermittent behavior due to click events coupled with the delay due to the timeout. Did you try removing the setTimeout so everything runs on the same thread?

Also, you still have the renderedView link stored in renderedViews[functionName], you should remove it at the same time as you run Blaze.remove to let the garbage collector do its job.

Yes, I had removed setTimeout and it still wasn’t working. I know, haven’t deleted it yet since Blaze.remove() wasn’t working as I’d hoped.

Set breakpoints in your browser and inspect what is happening. I have a feeling your problem is elsewhere / not related to Meteor.

Wow, major brain fart here. I came back to the problem today and realized my issue was that I was creating a new template even though it was found and I was removing it…

Thanks for the help