diff --git a/render/render.js b/render/render.js index 38aec09d..dfcd7bf3 100644 --- a/render/render.js +++ b/render/render.js @@ -248,6 +248,10 @@ module.exports = function($window) { vnode.dom = vnode.instance.dom vnode.domSize = vnode.instance.domSize } + else if (old.instance != null) { + removeNode(parent, old.instance, null, false) + vnode.dom = vnode.domSize = undefined + } } function isRecyclable(old, vnodes) { if (old.pool != null && Math.abs(old.pool.length - vnodes.length) <= Math.abs(old.length - vnodes.length)) { diff --git a/render/tests/test-component.js b/render/tests/test-component.js index 559da03e..828585c7 100644 --- a/render/tests/test-component.js +++ b/render/tests/test-component.js @@ -54,7 +54,7 @@ o.spec("component", function() { o(root.firstChild.attributes["id"].nodeValue).equals("c") o(root.firstChild.firstChild.nodeValue).equals("d") }) - o("updates from null", function() { + o("updates root from null", function() { var visible = false var component = { view: function(vnode) { @@ -67,7 +67,7 @@ o.spec("component", function() { o(root.firstChild.nodeName).equals("DIV") }) - o("updates from primitive", function() { + o("updates root from primitive", function() { var visible = false var component = { view: function(vnode) { @@ -80,6 +80,43 @@ o.spec("component", function() { o(root.firstChild.nodeName).equals("DIV") }) + o("updates root to null", function() { + var visible = true + var component = { + view: function(vnode) { + return visible ? {tag: "div"} : null + } + } + render(root, [{tag: component}]) + visible = false + render(root, [{tag: component}]) + + o(root.childNodes.length).equals(0) + }) + o("updates root to primitive", function() { + var visible = true + var component = { + view: function(vnode) { + return visible ? {tag: "div"} : false + } + } + render(root, [{tag: component}]) + visible = false + render(root, [{tag: component}]) + + o(root.firstChild.nodeValue).equals("false") + }) + o("updates root from null to null", function() { + var component = { + view: function(vnode) { + return null + } + } + render(root, [{tag: component}]) + render(root, [{tag: component}]) + + o(root.childNodes.length).equals(0) + }) o("removes", function() { var component = { view: function(vnode) {