@@ -7,6 +7,8 @@ import {cn} from '../../utils/cn';
77import { useTypedDispatch , useTypedSelector } from '../../utils/hooks' ;
88import { Portal } from '../Portal/Portal' ;
99
10+ import { useFullscreenContext } from './FullscreenContext' ;
11+
1012import disableFullscreenIcon from '../../assets/icons/disableFullscreen.svg' ;
1113
1214import './Fullscreen.scss' ;
@@ -21,11 +23,7 @@ interface FullscreenProps {
2123export function Fullscreen ( { children, className} : FullscreenProps ) {
2224 const isFullscreen = useTypedSelector ( ( state ) => state . fullscreen ) ;
2325 const dispatch = useTypedDispatch ( ) ;
24-
25- const fullscreenRoot = React . useMemo (
26- ( ) => document . getElementById ( 'fullscreen-root' ) ?? undefined ,
27- [ ] ,
28- ) ;
26+ const fullscreenRootRef = useFullscreenContext ( ) ;
2927
3028 const onDisableFullScreen = React . useCallback ( ( ) => {
3129 dispatch ( disableFullscreen ( ) ) ;
@@ -47,25 +45,25 @@ export function Fullscreen({children, className}: FullscreenProps) {
4745 const [ container , setContainer ] = React . useState < HTMLDivElement | null > ( null ) ;
4846 React . useEffect ( ( ) => {
4947 const div = document . createElement ( 'div' ) ;
50- fullscreenRoot ?. appendChild ( div ) ;
48+ fullscreenRootRef . current ?. appendChild ( div ) ;
5149 div . style . display = 'contents' ;
5250 setContainer ( div ) ;
5351 return ( ) => {
5452 setContainer ( null ) ;
5553 div . remove ( ) ;
5654 } ;
57- } , [ fullscreenRoot ] ) ;
55+ } , [ fullscreenRootRef ] ) ;
5856
5957 const ref = React . useRef < HTMLDivElement > ( null ) ;
6058 React . useLayoutEffect ( ( ) => {
6159 if ( container ) {
6260 if ( isFullscreen ) {
63- fullscreenRoot ?. appendChild ( container ) ;
61+ fullscreenRootRef . current ?. appendChild ( container ) ;
6462 } else {
6563 ref . current ?. appendChild ( container ) ;
6664 }
6765 }
68- } , [ container , fullscreenRoot , isFullscreen ] ) ;
66+ } , [ container , fullscreenRootRef , isFullscreen ] ) ;
6967
7068 if ( ! container ) {
7169 return null ;
0 commit comments