From 1b95bc280a02afcdfa627f54c620ae3c2f4e0d60 Mon Sep 17 00:00:00 2001 From: martin-mfg <2026226+martin-mfg@users.noreply.github.com> Date: Sun, 21 Sep 2025 12:01:04 +0200 Subject: [PATCH] try shadowDOMs --- frontend/frontend/src/components/Card/SVG.js | 44 ++++++++++---------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/frontend/frontend/src/components/Card/SVG.js b/frontend/frontend/src/components/Card/SVG.js index 6e680d0a..79f58e06 100644 --- a/frontend/frontend/src/components/Card/SVG.js +++ b/frontend/frontend/src/components/Card/SVG.js @@ -1,7 +1,7 @@ /* eslint-disable react/jsx-props-no-spreading */ /* eslint-disable react/no-danger */ -import React, { useEffect, useState } from 'react'; +import React, { useEffect, useRef, useState } from 'react'; import PropTypes from 'prop-types'; import Skeleton from 'react-loading-skeleton'; @@ -9,10 +9,8 @@ import 'react-loading-skeleton/dist/skeleton.css'; const SvgInline = (props) => { const [svg, setSvg] = useState(null); - - // eslint-disable-next-line no-unused-vars const [loaded, setLoaded] = useState(false); - + const containerRef = useRef(null); const { url } = props; useEffect(() => { @@ -24,6 +22,23 @@ const SvgInline = (props) => { .catch((e) => console.error(e)); }, [props.url]); + useEffect(() => { + if (loaded && svg && containerRef.current) { + // Attach shadow root if not already present + let shadow = containerRef.current.shadowRoot; + if (!shadow) { + shadow = containerRef.current.attachShadow({ mode: 'open' }); + } + // Clear previous content + shadow.innerHTML = ''; + // Insert SVG + const wrapper = document.createElement('div'); + wrapper.id = 'svg-card'; + wrapper.innerHTML = svg; + shadow.appendChild(wrapper); + } + }, [loaded, svg]); + if (props.forceLoading || !loaded) { if (props.compact) { return ; @@ -31,25 +46,8 @@ const SvgInline = (props) => { return ; } - if (props.compact) { - return ( -
${svg}
`, - }} - /> - ); - } - - return ( -
${svg}
`, - }} - /> - ); + // Render a container div for the shadow DOM + return
; }; SvgInline.propTypes = {