{"action":"opened","issue":{"url":"https://api.github.com/repos/meteor/meteor/issues/4950","labels_url":"https://api.github.com/repos/meteor/meteor/issues/4950/labels{/name}","comments_url":"https://api.github.com/repos/meteor/meteor/issues/4950/comments","events_url":"https://api.github.com/repos/meteor/meteor/issues/4950/events","html_url":"https://github.com/meteor/meteor/issues/4950","id":100677501,"number":4950,"title":"How to clean things up from DOM before Template.onDestroyed?","user":{"login":"trusktr","id":297678,"avatar_url":"https://avatars.githubusercontent.com/u/297678?v=3","gravatar_id":"","url":"https://api.github.com/users/trusktr","html_url":"https://github.com/trusktr","followers_url":"https://api.github.com/users/trusktr/followers","following_url":"https://api.github.com/users/trusktr/following{/other_user}","gists_url":"https://api.github.com/users/trusktr/gists{/gist_id}","starred_url":"https://api.github.com/users/trusktr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/trusktr/subscriptions","organizations_url":"https://api.github.com/users/trusktr/orgs","repos_url":"https://api.github.com/users/trusktr/repos","events_url":"https://api.github.com/users/trusktr/events{/privacy}","received_events_url":"https://api.github.com/users/trusktr/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-08-13T02:38:51Z","updated_at":"2015-08-13T02:38:51Z","closed_at":null,"body":"Based on the docs, it seems that `template.onDestroyed` fires after the DOM element for that template has already be removed. How do we do something with that DOM element before it is removed?\r\n\r\nSomething like `template.onBeforeDestroyed` would be a convenient way to access elements in the template to, for example, run `React.unmountComponentAtNode(template.$('.element-in-the-template'))`.\r\n\r\nRight now I'm doing\r\n\r\n```js\r\nTemplate.foo.onRendered(function() {\r\n    React.render(\r\n        <div>blah</div>,\r\n        this.$('.element-in-the-template')[0]\r\n    )\r\n})\r\n```\r\n\r\nNow, when the blaze template `foo` gets destroyed, the DOM for the `foo` template is already gone when onDestroyed is called (I believe, based on the fact that we can't use template.$, etc), so how do I unmount my React component from the DOM of the Blaze template if the DOM is gone?\r\n\r\nWill we have a memory leak now that React has a reference to the DOM that was previously in the Blaze template and there's no way to get that reference in order to unmount the React component?"}}