Don't cleanup StyledShadow on unmount
This commit is contained in:
parent
ed6d74db87
commit
a8a533cb73
1 changed files with 16 additions and 6 deletions
|
@ -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>(
|
||||||
|
|
Loading…
Reference in a new issue