fix(web): inject app styles into isolated HTML

- clone loaded application style nodes into the Shadow DOM for custom HTML rendering.
- keep HTML rendering isolated while restoring layout and typography that depend on app CSS.
This commit is contained in:
QuentinHsu committed 2026-07-02 17:49:10 +08:00
1 parent 52858ad1e6
commit 53c8bdc68c
1 file changed
+15 -2
+15 -2
View File
@@ -142,11 +142,24 @@ function IsolatedHtmlContent(props: {
useEffect(() => {
const container = containerRef.current
if (!container) return
if (!container) {
return
}
const shadowRoot =
container.shadowRoot ?? container.attachShadow({ mode: 'open' })
shadowRoot.innerHTML = `${isolatedContentBaseStyles}${props.html}`
const applicationStyleNodes = [
...document.head.querySelectorAll<HTMLLinkElement | HTMLStyleElement>(
'style, link[rel="stylesheet"]'
),
].map((node) => node.cloneNode(true))
const contentTemplate = document.createElement('template')
contentTemplate.innerHTML = `${isolatedContentBaseStyles}${props.html}`
shadowRoot.replaceChildren(
...applicationStyleNodes,
contentTemplate.content
)
}, [props.html])
return (