diff --git a/src/client/updaters/attribute.js b/src/client/updaters/attribute.js index e3cf648..4808f74 100644 --- a/src/client/updaters/attribute.js +++ b/src/client/updaters/attribute.js @@ -7,27 +7,31 @@ export default function updateAttribute({ attribute } = {}, attrs, tag) { const vueMetaAttrString = tag.getAttribute(attribute) const vueMetaAttrs = vueMetaAttrString ? vueMetaAttrString.split(',') : [] - const toRemove = [].concat(vueMetaAttrs) + const toRemove = Array.from(vueMetaAttrs) + const keepIndexes = [] for (const attr in attrs) { if (attrs.hasOwnProperty(attr)) { - const val = attrs[attr] || '' - tag.setAttribute(attr, val) + const value = attrs[attr] || '' + tag.setAttribute(attr, value) if (!vueMetaAttrs.includes(attr)) { vueMetaAttrs.push(attr) } - const keepIndex = toRemove.indexOf(attr) - if (keepIndex !== -1) { - toRemove.splice(keepIndex, 1) - } + // filter below wont ever check -1 + keepIndexes.push(toRemove.indexOf(attr)) } } - toRemove.forEach(attr => tag.removeAttribute(attr)) + const removedAttributesCount = toRemove + .filter((el, index) => !keepIndexes.includes(index)) + .reduce((acc, attr) => { + tag.removeAttribute(attr) + return acc + 1 + }, 0) - if (vueMetaAttrs.length === toRemove.length) { + if (vueMetaAttrs.length === removedAttributesCount) { tag.removeAttribute(attribute) } else { tag.setAttribute(attribute, (vueMetaAttrs.sort()).join(','))