How to properly deal with portal containers and the fullscreen API? #9206
|
Hello gents, My app is using the DOM fullscreen API for several cases. Let's consider two of them:
By default, case 1 does not work because as soon as the component goes fullscreen, the What I thought was a very smart move was to use the PortalProvider… despite the fact that it was flagged "UNSAFE". export function SkPortalProvider(props: { children: ReactNode }) {
return <UNSAFE_PortalProvider getContainer={getDomRoot}>{props.children}</UNSAFE_PortalProvider>;
}
function getDomRoot(): HTMLElement | null {
return document?.fullscreenElement instanceof HTMLElement ? document.fullscreenElement : document.body;
}Clever, ugh? Actually not so much because then, case 2 won't work any longer : as soon as the video goes fullscreen, the portal is changed, so that the dialog containing the video node vanishes… Then I tried to be more clever than ever 😁… function getDomRoot(): HTMLElement | null {
// If there are existing modals/dialogs in document.body, keep using document.body
// to avoid moving them when fullscreen is triggered. This prevents modals from
// disappearing when fullscreen is activated.
const hasExistingModals = document.body?.querySelector('[role="dialog"], [role="alertdialog"]') != null;
if (hasExistingModals) {
return document.body;
}
// Otherwise, use fullscreen element if available (for popovers within fullscreen),
// or document.body as fallback
return document?.fullscreenElement instanceof HTMLElement ? document.fullscreenElement : document.body;
}… but then case 1 no longer works properly… Hence my questions: did you guys consider using/supporting fullscreen? How did you do? Many thanks in advance 🙏 |
Replies: 2 comments 5 replies
|
Thanks for the discussion. We created the PortalProvider partially because someone needed to make use of fullscreen. It doesn't look like the group that needed fullscreen support contributed any tests however and we don't make use of it ourselves at the moment, so there may be some gaps we're unaware of. Would you be willing to put together a small test app in codesandbox or stackblitz or even in our storybook? That's probably the easiest way to diagnose what's going on or if it's just differing expectations. At the very least, I think you're on the right track |
|
Hi @snowystinger ! |
I've converted it to an issue, #10506
Apologies, I've not had time to think about it :(
It would be interesting to see if an AI can find any prior art around this issue. Maybe that would be a good starting point for figuring out how we'd like to solve it.