Batched state changes are not flushed if the promise code changes the DOM (= attaching an iframe). Reproduceable with Safari.

React version: 18.1.0

## Steps To Reproduce

1. Open [codepen](https://codepen.io/kh-viewar/pen/wvpVLxM) with Safari.
2. Click "Upload"
3. => "Spinner" text does not render while Promise is in pending

Link to code example:

https://codepen.io/kh-viewar/pen/wvpVLxM

## The current behavior

State changes are not executed.

## The expected behavior

State should change to true and render spinner component. After promise is resolved (2 seconds timeout), state should switch back to false and spinner component should unmount.

## Original discussion

https://github.com/facebook/react/issues/24365
try {
    return fn(a);
  } finally {
    executionContext = prevExecutionContext;
     
     
    if (
      executionContext === NoContext &&
       
      !(__DEV__ && ReactCurrentActQueue.isBatchingLegacy)
    ) {
      resetRenderTimer();
      flushSyncCallbacksOnlyInLegacyMode();
    }
  }
}
export function discreteUpdates<A, B, C, D, R>(
  fn: (A, B, C, D) => R,
  a: A,
  b: B,
  c: C,
  d: D,
): R {
  const previousPriority = getCurrentUpdatePriority();
  const prevTransition = ReactCurrentBatchConfig.transition;
  try {
    ReactCurrentBatchConfig.transition = null;
    setCurrentUpdatePriority(DiscreteEventPriority);
    return fn(a, b, c, d);
  } finally {