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(() => {
if (!template) return
const shadowRoot = (template.parentNode as HTMLElement).attachShadow({
const {parentNode} = template
if (!parentNode) return
const hadShadowRoot =
// @ts-ignore
!!parentNode.shadowRoot
const shadowRoot = hadShadowRoot
? // @ts-ignore
parent.shadowRoot
: (parentNode as HTMLElement).attachShadow({
mode: 'open',
})
setShadowRoot(shadowRoot)
return () => {
template.parentNode?.removeChild(shadowRoot)
}
// no need to cleanup. The parent will be removed anyway if cleanup
// is needed.
}, [template])
const [portalLayerRef, portalLayer] = useRefAndState<HTMLDivElement>(