From 606a0488eb6c6399592815367551558485032b4b Mon Sep 17 00:00:00 2001 From: Mike Date: Sun, 23 May 2021 11:57:28 -0700 Subject: [PATCH] fix: avoid className check to handle SVG elements within shadow DOM (#965) --- src/init.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/init.ts b/src/init.ts index 12afe49..8483072 100644 --- a/src/init.ts +++ b/src/init.ts @@ -86,7 +86,12 @@ export function init(modules: Array>, domApi?: DOMAPI) { function emptyNodeAt(elm: Element) { const id = elm.id ? "#" + elm.id : ""; - const c = elm.className ? "." + elm.className.split(" ").join(".") : ""; + + // elm.className doesn't return a string when elm is an SVG element inside a shadowRoot. + // https://stackoverflow.com/questions/29454340/detecting-classname-of-svganimatedstring + const classes = elm.getAttribute("class"); + + const c = classes ? "." + classes.split(" ").join(".") : ""; return vnode( api.tagName(elm).toLowerCase() + id + c, {},