[Bug] ToastViewport renders behind a Dialog that opens after the viewport mounted
Description
Expected: the toast shows above the dialog and its backdrop.
Actual: the toast renders behind the dialog's backdrop.
Cause: top-layer elements stack in the order they entered the top layer, with the last one on top.
ToastViewport enters only once, through showPopover() in its mount effect. Dialog enters each time it opens, through showModal(). So any dialog opened after the viewport mounted covers it. It only works when no viewport exists before the dialog opens. In that case useToast creates the fallback viewport on the first toast, which is after the dialog.
Reproduction
- Render a ToastViewport at the app root (default isTopLayer).
- Open a Dialog.
- Call toast() from a control inside the dialog.
import { ToastViewport, useToast } from "@astryxdesign/core/Toast";
import { Dialog, DialogHeader } from "@astryxdesign/core/Dialog";
import { Layout, LayoutContent } from "@astryxdesign/core/Layout";
import { Button } from "@astryxdesign/core/Button";
function Inner() {
const [isOpen, setIsOpen] = useState(false);
const toast = useToast();
return (
<>
<Button label="Open dialog" onClick={() => setIsOpen(true)} />
<Dialog isOpen={isOpen} onOpenChange={setIsOpen}>
<Layout
header={<DialogHeader title="Dialog" onOpenChange={setIsOpen} />}
content={
<LayoutContent>
<Button label="Show toast" onClick={() => toast({ type: "info", body: "Hello" })} />
</LayoutContent>
}
/>
</Dialog>
</>
);
}
export function Repro() {
return (
<ToastViewport>
<Inner />
</ToastViewport>
);
}```
### Astryx Version
@astryxdesign/core 0.6.1
### Environment
Seen in Chromium; other browsers not tested.
reproduced against the current main, will be raising a pr soon for this, thanks!
If Meta added a web browser tab directly inside Facebook, it would literally crush Google and it could even become the most profitable startup in the world given the number of Facebook users, you can do everything on Facebook, no need to install Google anymore