From 39ff8d721740ffa8ff038f65055de1f1d2160d0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Yves=20G=C3=A9rardy?= Date: Wed, 22 Nov 2017 00:05:34 +0100 Subject: [PATCH] render: make removeNode aware that it is removing children from an object that's brought back from the pool --- render/render.js | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/render/render.js b/render/render.js index 1e3f3fef..61f8f9a6 100644 --- a/render/render.js +++ b/render/render.js @@ -164,7 +164,7 @@ module.exports = function($window) { function updateNodes(parent, old, vnodes, recyclingParent, hooks, nextSibling, ns) { if (old === vnodes && !recyclingParent || old == null && vnodes == null) return else if (old == null) createNodes(parent, vnodes, 0, vnodes.length, hooks, nextSibling, ns) - else if (vnodes == null) removeNodes(old, 0, old.length, vnodes) + else if (vnodes == null) removeNodes(old, 0, old.length, vnodes, recyclingParent) else { var start = 0, commonLength = Math.min(old.length, vnodes.length), originalOldLength = old.length, hasPool = false, isUnkeyed for(; start < commonLength; start++) { @@ -182,7 +182,7 @@ module.exports = function($window) { for (; start < originalOldLength; start++) { if (old[start] === vnodes[start] && !recyclingParent || old[start] == null && vnodes[start] == null) continue else if (old[start] == null) createNode(parent, vnodes[start], hooks, ns, getNextSibling(old, start + 1, originalOldLength, nextSibling)) - else if (vnodes[start] == null) removeNodes(old, start, start + 1, null) + else if (vnodes[start] == null) removeNodes(old, start, start + 1, vnodes, recyclingParent) else updateNode(parent, old[start], vnodes[start], hooks, getNextSibling(old, start + 1, originalOldLength, nextSibling), recyclingParent, ns) } return @@ -207,7 +207,7 @@ module.exports = function($window) { oldStart++ } else if (v == null) { if (isUnkeyed){ - removeNodes(old, start, start + 1, vnodes) + removeNodes(old, start, start + 1, vnodes, recyclingParent) oldStart++ } start++ @@ -262,7 +262,7 @@ module.exports = function($window) { if (end < start) break } createNodes(parent, vnodes, start, end + 1, hooks, nextSibling, ns) - removeNodes(old, oldStart, Math.min(oldEnd + 1, originalOldLength), vnodes) + removeNodes(old, oldStart, Math.min(oldEnd + 1, originalOldLength), vnodes, recyclingParent) if (hasPool) { var limit = Math.max(oldStart, originalOldLength) for (; oldEnd >= limit; oldEnd--) { @@ -296,7 +296,7 @@ module.exports = function($window) { else updateComponent(parent, old, vnode, hooks, nextSibling, recycling, ns) } else { - removeNode(old, null) + removeNode(old, null, recycling) createNode(parent, vnode, hooks, ns, nextSibling) } } @@ -368,7 +368,7 @@ module.exports = function($window) { vnode.domSize = vnode.instance.domSize } else if (old.instance != null) { - removeNode(old.instance, null) + removeNode(old.instance, null, recycling) vnode.dom = undefined vnode.domSize = 0 } @@ -434,37 +434,41 @@ module.exports = function($window) { } //remove - function removeNodes(vnodes, start, end, context) { + function removeNodes(vnodes, start, end, context, recycling) { for (var i = start; i < end; i++) { var vnode = vnodes[i] if (vnode != null) { if (vnode.skip) vnode.skip = false - else removeNode(vnode, context) + else removeNode(vnode, context, recycling) } } } - function removeNode(vnode, context) { + function removeNode(vnode, context, recycling) { var expected = 1, called = 0 var original = vnode.state - if (vnode.attrs && typeof vnode.attrs.onbeforeremove === "function") { - var result = callHook.call(vnode.attrs.onbeforeremove, vnode) - if (result != null && typeof result.then === "function") { - expected++ - result.then(continuation, continuation) + if (!recycling) { + if (vnode.attrs && typeof vnode.attrs.onbeforeremove === "function") { + var result = callHook.call(vnode.attrs.onbeforeremove, vnode) + if (result != null && typeof result.then === "function") { + expected++ + result.then(continuation, continuation) + } } - } - if (typeof vnode.tag !== "string" && typeof vnode.state.onbeforeremove === "function") { - var result = callHook.call(vnode.state.onbeforeremove, vnode) - if (result != null && typeof result.then === "function") { - expected++ - result.then(continuation, continuation) + if (typeof vnode.tag !== "string" && typeof vnode.state.onbeforeremove === "function") { + var result = callHook.call(vnode.state.onbeforeremove, vnode) + if (result != null && typeof result.then === "function") { + expected++ + result.then(continuation, continuation) + } } } continuation() function continuation() { if (++called === expected) { - checkState(vnode, original) - onremove(vnode) + if (!recycling) { + checkState(vnode, original) + onremove(vnode) + } if (vnode.dom) { var count = vnode.domSize || 1 if (count > 1) {