From a72f92af11d8226522f7a1b6a6273caf1978d1c8 Mon Sep 17 00:00:00 2001 From: Hayleigh Thompson Date: Sun, 20 Aug 2023 07:46:44 +0100 Subject: :recycle: Tweak class concat code to avoid leading whitespace. --- lib/src/runtime.ffi.mjs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/src/runtime.ffi.mjs b/lib/src/runtime.ffi.mjs index 1d25d6f..3fc0d91 100644 --- a/lib/src/runtime.ffi.mjs +++ b/lib/src/runtime.ffi.mjs @@ -43,7 +43,9 @@ function createElement(prev, curr, ns, parent = null) { morphAttr( el, attr.head[0], - attr.head[0] === "class" ? `${el.className}{attr.head[1]}` : attr.head[1] + attr.head[0] === "class" && el.className + ? `${el.className} ${attr.head[1]}` + : attr.head[1] ); attr = attr.tail; @@ -77,6 +79,7 @@ function createElement(prev, curr, ns, parent = null) { if (prev) prev.replaceWith(el); } + return el; } @@ -88,8 +91,8 @@ function morphElement(prev, curr, ns, parent) { while (currAttr.head) { currAttrs.set( currAttr.head[0], - currAttr.head[0] === "class" - ? `${prev.className} {currAttr.head[1]}` + currAttr.head[0] === "class" && prev.className + ? `${prev.className} ${currAttr.head[1]}` : currAttr.head[1] ); -- cgit v1.2.3