message: fix: Fix `MenuDisclosure` race condition on focus/click
diff: @@ -24,17 +24,29 @@ export function useMenuDisclosure(
  ) {
  const parent = React.useContext(MenuContext);
  const ref = React.useRef<HTMLElement>(null);
  + // This avoids race condition between focus and click.
  + // On some browsers, focus is triggered right before click.
  + // So we use it to disable toggling.
  + const [hasShownOnFocus, setHasShownOnFocus] = React.useState(false);
  options = unstable_useOptions("useMenuDisclosure", options, htmlProps);
  const dir = options.placement ? options.placement.split("-")[0] : undefined;
  + // Restores hasShownOnFocus state when it's closed
  + React.useEffect(() => {
  + if (!options.visible) {
  + setHasShownOnFocus(false);
  + }
  + }, [options.visible]);
  +
  htmlProps = mergeProps(
  {
  ref,
  "aria-haspopup": "menu",
  onFocus: () => {
  if (parent && parent.orientation === "horizontal") {
  + setHasShownOnFocus(true);
  options.show();
  }
  },
  @@ -95,7 +107,7 @@ export function useMenuDisclosure(
  {
  ...options,
  toggle:
  - parent && parent.orientation !== "horizontal"
  + parent && (parent.orientation !== "horizontal" || hasShownOnFocus)
  ? options.show
  : options.toggle
  },
  