Skip to content

Commit dac65c1

Browse files
committed
act: Move didScheduleLegacyUpdate to ensureRootIsScheduled
`act` uses the `didScheduleLegacyUpdate` field to simulate the behavior of batching in React <17 and below. It's a quirk leftover from a previous implementation, not intentionally designed. This sets `didScheduleLegacyUpdate` every time a legacy root receives an update as opposed to only when the `executionContext` is empty. There's no real reason to do it this way over some other way except that it's how it used to work before facebook#26512 and we should try our best to maintain the existing behavior, quirks and all, since existing tests may have come to accidentally rely on it. This should fix some (though not all) of the internal Meta tests that started failing after facebook#26512 landed.
1 parent d5fd60f commit dac65c1

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

packages/react-reconciler/src/ReactFiberRootScheduler.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,15 @@ export function ensureRootIsScheduled(root: FiberRoot): void {
119119
// unblock additional features we have planned.
120120
scheduleTaskForRootDuringMicrotask(root, now());
121121
}
122+
123+
if (
124+
__DEV__ &&
125+
ReactCurrentActQueue.isBatchingLegacy &&
126+
root.tag === LegacyRoot
127+
) {
128+
// Special `act` case: Record whenever a legacy update is scheduled.
129+
ReactCurrentActQueue.didScheduleLegacyUpdate = true;
130+
}
122131
}
123132

124133
export function flushSyncWorkOnAllRoots() {

packages/react-reconciler/src/ReactFiberWorkLoop.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,6 @@ export function scheduleUpdateOnFiber(
828828
) {
829829
if (__DEV__ && ReactCurrentActQueue.isBatchingLegacy) {
830830
// Treat `act` as if it's inside `batchedUpdates`, even in legacy mode.
831-
ReactCurrentActQueue.didScheduleLegacyUpdate = true;
832831
} else {
833832
// Flush the synchronous work now, unless we're already working or inside
834833
// a batch. This is intentionally inside scheduleUpdateOnFiber instead of

0 commit comments

Comments
 (0)