message: fix: Fix `Dialog` triggering `autoFocusOnShow` with dynamic nested dialogs
diff: @@ -25,6 +25,7 @@ import {
  import {
  useBooleanEventCallback,
  useForkRef,
  + useLiveRef,
  useSafeLayoutEffect,
  useWrapElement,
  } from "ariakit-utils/hooks";
  @@ -135,6 +136,7 @@ export const useDialog = createHook<DialogOptions>(
  const nested = useNestedDialogs(ref, { state, modal });
  const { nestedDialogs, visibleModals, wrapElement } = nested;
  + const nestedDialogsRef = useLiveRef(nestedDialogs);
  usePreventBodyScroll(preventBodyScroll && state.mounted);
  // When the dialog is unmounted, we make sure to update the state.
  @@ -241,9 +243,8 @@ export const useDialog = createHook<DialogOptions>(
  // focus. This is useful for when the Dialog component is unmounted
  // when hidden.
  if (!domReady) return;
  -
  // If there are open nested dialogs, let them handle the focus.
  - const isNestedDialogVisible = nestedDialogs.some(
  + const isNestedDialogVisible = nestedDialogsRef.current?.some(
  (child) => child.current && !child.current.hidden
  );
  if (isNestedDialogVisible) return;
  @@ -264,7 +265,6 @@ export const useDialog = createHook<DialogOptions>(
  state.visible,
  autoFocusOnShow,
  domReady,
  - nestedDialogs,
  initialFocusRef,
  portal,
  preserveTabOrder,
  