mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-09-06 17:46:23 +00:00
fix(web): inject app styles into isolated HTML (#5860)
- 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:
+15
-2
@@ -142,11 +142,24 @@ function IsolatedHtmlContent(props: {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const container = containerRef.current
|
const container = containerRef.current
|
||||||
if (!container) return
|
if (!container) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const shadowRoot =
|
const shadowRoot =
|
||||||
container.shadowRoot ?? container.attachShadow({ mode: 'open' })
|
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])
|
}, [props.html])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user