[drawer] After eventDetails.cancel() on a close-watcher close, the next Back leaves the page
Bug report
Current behavior
On Android, Drawer.Root creates one CloseWatcher per open and closes on its close event. If onOpenChange cancels that close with eventDetails.cancel(), the drawer stays open but the watcher is gone: it fired and is not re-created, since the effect only re-runs when open changes. The next Back press is a history back and leaves the page with the drawer still open.
Expected behavior
After a cancelled close-watcher close, Back should reach the drawer again, the way it does for a native <dialog>.
Reproducible example
import { Drawer } from '@base-ui/react/drawer';
import { useState } from 'react';
export function Repro() {
const [open, setOpen] = useState(false);
const [step, setStep] = useState(0);
return (
<Drawer.Root
open={open}
onOpenChange={(next, details) => {
if (next || step === 0) return setOpen(next);
details.cancel();
setStep((s) => s - 1); // Back steps through the drawer's content first
}}
>
<Drawer.Trigger onClick={() => setStep(2)}>Open</Drawer.Trigger>
<Drawer.Portal>
<Drawer.Backdrop />
<Drawer.Viewport>
<Drawer.Popup>
<Drawer.Content>step {step}</Drawer.Content>
</Drawer.Popup>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
);
}
On Android Chrome: open, press Back → step 1 (good). Press Back again → the page navigates away; the drawer never sees it.
Where it happens: packages/react/src/drawer/root/DrawerRoot.tsx, the CloseWatcher effect ([store, isTopmost, open, popupElement] deps, close listener only). Re-creating the watcher after a cancelled close, or listening to the watcher's cancel event so the platform can honour the cancel once per user activation, would both fix it.
Base UI version
1.8.0 (same code on master)
Which browser are you using?
Chrome on Android (the watcher is Android-only). Also reproducible in desktop Chromium with an Android user agent, where Escape is the close request.
Which OS are you using?
Android
This fix will be available in the next npm release of Base UI.
In the meantime, use the canary build from PR #5770:
npm i https://pkg.pr.new/@base-ui/react@82d7a86
This installs a complete package for @base-ui/react with the fix included. It is hosted by pkg.pr.new rather than npm, and the URL is available for up to six months.