From 3f5114d3ad44347763e5b53e69b31c38e38f9a97 Mon Sep 17 00:00:00 2001 From: Hayleigh Thompson Date: Tue, 22 Aug 2023 23:33:25 +0100 Subject: :bug: Fixed a regression where an elements classes would duplicate every render. --- lib/src/runtime.ffi.mjs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'lib/src') diff --git a/lib/src/runtime.ffi.mjs b/lib/src/runtime.ffi.mjs index 3fc0d91..59c5883 100644 --- a/lib/src/runtime.ffi.mjs +++ b/lib/src/runtime.ffi.mjs @@ -91,8 +91,8 @@ function morphElement(prev, curr, ns, parent) { while (currAttr.head) { currAttrs.set( currAttr.head[0], - currAttr.head[0] === "class" && prev.className - ? `${prev.className} ${currAttr.head[1]}` + currAttr.head[0] === "class" && currAttrs.has("class") + ? `${currAttrs.get("class")} ${currAttr.head[1]}` : currAttr.head[1] ); @@ -176,7 +176,7 @@ function morphElement(prev, curr, ns, parent) { function morphAttr(el, name, value) { switch (typeof value) { case "string": - el.setAttribute(name, value); + if (el.getAttribute(name) !== value) el.setAttribute(name, value); break; // Boolean attributes work a bit differently in HTML. Their presence always @@ -223,6 +223,11 @@ function toJsValue(value) { // TEXT ------------------------------------------------------------------------ function createText(prev, curr) { + if (!curr[0]) { + prev?.remove(); + return null; + } + const el = document.createTextNode(curr[0]); if (prev) prev.replaceWith(el); @@ -233,6 +238,11 @@ function morphText(prev, curr) { const prevValue = prev.nodeValue; const currValue = curr[0]; + if (!currValue) { + prev?.remove(); + return null; + } + if (prevValue !== currValue) prev.nodeValue = currValue; return prev; -- cgit v1.2.3