SIGN IN SIGN UP
facebook / react-native UNCLAIMED

A framework for building native applications using React

0 0 0 C++

Attempt to reduce flakyness on Modal-itest "MessageQueue is not empty" failure (#55486)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/55486

The Modal integration test `<Modal> › ref › instance › uses the "RN:ModalHostView" tag name` was flaky on CI, intermittently failing with "MessageQueue is not empty" during the global afterEach `validateEmptyMessageQueue` hook.

The root cause is that when Modal renders in __DEV__ mode, AppContainer's `useEffect` schedules passive effects as a deferred task on the RuntimeScheduler. Due to how microtask scheduling interacts with the RuntimeScheduler drain loop in Hermes, `flushMessageQueue()` inside `runTask` occasionally returns before this task is fully processed, leaving it on the queue for `validateEmptyMessageQueue` to find.

The fix adds an `afterEach` hook at the top-level `describe('<Modal>')` block that calls `Fantom.runWorkLoop()`. This provides a second drain pass before the global `validateEmptyMessageQueue` check runs (inner afterEach hooks execute before outer ones). The call is a no-op when the queue is already empty, so it adds no overhead to tests where the initial drain was complete.

This is consistent with patterns in Fantom-itest.js where Modal tests that call additional `runWorkLoop()` (for `enqueueModalSizeUpdate`) never exhibit this flakiness, precisely because that second drain catches any residual passive effects work.

Changelog:
[Internal] [Changed] -

Reviewed By: rubennorte

Differential Revision: D92828076

fbshipit-source-id: 529abe962044e2da6bee3b1e2ef4b129392fae06
N
Nicola Corti committed
233ee9d44d43eb4f9d585268f0641b8a2b34334a
Parent: 4356259
Committed by meta-codesync[bot] <215208954+meta-codesync[bot]@users.noreply.github.com> on 2/11/2026, 2:45:00 PM