From c46567ab81fa6ff5b8750b5c6a18667fb1dc10d8 Mon Sep 17 00:00:00 2001 From: Greg King Date: Wed, 29 Jul 2015 09:40:32 -0400 Subject: [PATCH] #745 Remove references to DOM nodes when unmounting When a null component is passed into m.mount(), remove references to the root DOM element from: - roots - cellCache - nodeCache And remove the associated entries from: - controllers - components --- mithril.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/mithril.js b/mithril.js index 080c6052..c3f9e657 100644 --- a/mithril.js +++ b/mithril.js @@ -764,6 +764,8 @@ var m = (function app(window, undefined) { controllers[index].onunload(event); } + var isNullComponent = component === null; + if (!isPrevented) { m.redraw.strategy("all"); m.startComputation(); @@ -777,14 +779,24 @@ var m = (function app(window, undefined) { components[index] = component; } endFirstComputation(); + if (isNullComponent) { + removeRootElement(root, index); + } return controllers[index]; } - if (!component) { - roots.splice(index, 1); - controllers.splice(index, 1); - components.splice(index, 1); + if (isNullComponent) { + removeRootElement(root, index); } }; + + function removeRootElement(root, index) { + roots.splice(index, 1); + controllers.splice(index, 1); + components.splice(index, 1); + reset(root); + nodeCache.splice(getCellCacheKey(root), 1); + } + var redrawing = false, forcing = false; m.redraw = function(force) { if (redrawing) return;