astryx icon indicating copy to clipboard operation
astryx copied to clipboard

[Bug] ToastViewport renders behind a Dialog that opens after the viewport mounted

Open inesgomas opened this issue 1 month ago • 2 comments

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

  1. Render a ToastViewport at the app root (default isTopLayer).
  2. Open a Dialog.
  3. 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.

inesgomas avatar Oct 06 '26 10:10 inesgomas

reproduced against the current main, will be raising a pr soon for this, thanks!

Geervan avatar Oct 06 '26 10:10 Geervan

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

fenocicinho-prog avatar Oct 06 '26 14:10 fenocicinho-prog