Don't cleanup StyledShadow on unmount

This commit is contained in:
Aria Minaei 2023-08-05 10:01:44 +02:00
parent ed6d74db87
commit a8a533cb73

View file

@ -113,14 +113,24 @@ const ProvideStyledShadow: React.FC<{
useLayoutEffect(() => { useLayoutEffect(() => {
if (!template) return if (!template) return
const shadowRoot = (template.parentNode as HTMLElement).attachShadow({ const {parentNode} = template
mode: 'open', if (!parentNode) return
})
const hadShadowRoot =
// @ts-ignore
!!parentNode.shadowRoot
const shadowRoot = hadShadowRoot
? // @ts-ignore
parent.shadowRoot
: (parentNode as HTMLElement).attachShadow({
mode: 'open',
})
setShadowRoot(shadowRoot) setShadowRoot(shadowRoot)
return () => { // no need to cleanup. The parent will be removed anyway if cleanup
template.parentNode?.removeChild(shadowRoot) // is needed.
}
}, [template]) }, [template])
const [portalLayerRef, portalLayer] = useRefAndState<HTMLDivElement>( const [portalLayerRef, portalLayer] = useRefAndState<HTMLDivElement>(