fix: duplicate portal container temporary fix

This commit is contained in:
Hossein Mehrabi 2023-10-23 10:28:23 +03:30
parent 65bebb8326
commit 868ab6ca7a
No known key found for this signature in database
GPG Key ID: 45C04964191AFAA1
1 changed files with 7 additions and 3 deletions

View File

@ -1,5 +1,6 @@
import React, { useEffect, useState } from 'react'
import { PortalContext } from './PortalContext'
import { settleSync } from '../../utils/promise.utils'
export type PortalProviderProps = React.PropsWithChildren
@ -10,14 +11,17 @@ export const PortalProvider: React.FC<PortalProviderProps> = ({ children }) => {
if (typeof window === 'undefined') return
const body = document.querySelector('body')!
const container = document.createElement('div')
container.id = 'lsd-presentation'
let container = body.querySelector('#lsd-presentation')
if (!container) {
container = document.createElement('div')
container.id = 'lsd-presentation'
}
body.appendChild(container)
setInitialized(true)
return () => {
body.removeChild(container)
settleSync(() => body.removeChild(container!))
}
}, [])