diff --git a/src/directives/for.js b/src/directives/for.js index 5d274c6..db027e1 100644 --- a/src/directives/for.js +++ b/src/directives/for.js @@ -48,7 +48,7 @@ const reconcile = (context, element, prevList, nextList, key) => { // REMOVE ELEMENTS if (gap < 0) { - removeParts(element, index); + removeParts(element, index, index - gap); } }; diff --git a/src/directives/template.js b/src/directives/template.js index 3401ab9..5ecc421 100644 --- a/src/directives/template.js +++ b/src/directives/template.js @@ -123,8 +123,9 @@ export const updatePart = (template, index, value) => { * remove a DOM part from the DOM and disconnect it * @param {HTMLTemplateElement} template * @param {number} index + * @param {number} length */ -export const removeParts = (template, index) => { +export const removeParts = (template, index, length) => { /** @type {Array} */ const parts = template.templateParts; @@ -133,7 +134,7 @@ export const removeParts = (template, index) => { const head = parts[index].flag; // remove all the nodes between head and tail for all parts - while (index++ < parts.length - 1) { + while (index++ < length) { // get the current comparison node let currentNode = nextSiblingOf(head); // retrieve the current part tail