Skip to content

Commit 5c1cf56

Browse files
committed
Add flag to disable behavior change
1 parent 675b576 commit 5c1cf56

12 files changed

+42
-2
lines changed

packages/react-reconciler/src/ReactFiberRootScheduler.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type {FiberRoot} from './ReactInternalTypes';
1111
import type {Lane} from './ReactFiberLane';
1212
import type {PriorityLevel} from 'scheduler/src/SchedulerPriorities';
1313

14+
import {enableDeferRootSchedulingToMicrotask} from 'shared/ReactFeatureFlags';
1415
import {
1516
NoLane,
1617
NoLanes,
@@ -111,6 +112,14 @@ export function ensureRootIsScheduled(root: FiberRoot): void {
111112
scheduleImmediateTask(processRootScheduleInMicrotask);
112113
}
113114
}
115+
116+
if (!enableDeferRootSchedulingToMicrotask) {
117+
// While this flag is disabled, we schedule the render task immediately
118+
// instead of waiting a microtask.
119+
// TODO: We need to land enableDeferRootSchedulingToMicrotask ASAP to
120+
// unblock additional features we have planned.
121+
scheduleTaskForRootDuringMicrotask(root, now());
122+
}
114123
}
115124

116125
export function flushSyncWorkOnAllRoots() {
@@ -263,6 +272,9 @@ function scheduleTaskForRootDuringMicrotask(
263272
// rendering task right before we yield to the main thread. It should never be
264273
// called synchronously.
265274
//
275+
// TODO: Unless enableDeferRootSchedulingToMicrotask is off. We need to land
276+
// that ASAP to unblock additional features we have planned.
277+
//
266278
// This function also never performs React work synchronously; it should
267279
// only schedule work to be performed later, in a separate task or microtask.
268280

packages/react/src/__tests__/ReactProfiler-test.internal.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,22 @@ describe(`onRender`, () => {
258258

259259
// TODO: unstable_now is called by more places than just the profiler.
260260
// Rewrite this test so it's less fragile.
261-
assertLog(['read current time', 'read current time', 'read current time']);
261+
if (gate(flags => flags.enableDeferRootSchedulingToMicrotask)) {
262+
assertLog([
263+
'read current time',
264+
'read current time',
265+
'read current time',
266+
]);
267+
} else {
268+
assertLog([
269+
'read current time',
270+
'read current time',
271+
'read current time',
272+
'read current time',
273+
'read current time',
274+
'read current time',
275+
]);
276+
}
262277

263278
// Restore original mock
264279
jest.mock('scheduler', () => jest.requireActual('scheduler/unstable_mock'));

packages/shared/ReactFeatureFlags.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ export const enableSchedulerDebugging = false;
4848
// Need to remove didTimeout argument from Scheduler before landing
4949
export const disableSchedulerTimeoutInWorkLoop = false;
5050

51+
// This will break some internal tests at Meta so we need to gate this until
52+
// those can be fixed.
53+
export const enableDeferRootSchedulingToMicrotask = true;
54+
5155
// -----------------------------------------------------------------------------
5256
// Slated for removal in the future (significant effort)
5357
//

packages/shared/forks/ReactFeatureFlags.native-fb-dynamic.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import typeof * as DynamicFlagsType from 'ReactNativeInternalFeatureFlags';
2121
// update the test configuration.
2222

2323
export const enableUseRefAccessWarning = __VARIANT__;
24+
export const enableDeferRootSchedulingToMicrotask = __VARIANT__;
2425

2526
// Flow magic to verify the exports of this file match the original version.
2627
((((null: any): ExportsType): DynamicFlagsType): ExportsType);

packages/shared/forks/ReactFeatureFlags.native-fb.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import * as dynamicFlags from 'ReactNativeInternalFeatureFlags';
1717

1818
// We destructure each value before re-exporting to avoid a dynamic look-up on
1919
// the exports object every time a flag is read.
20-
export const {enableUseRefAccessWarning} = dynamicFlags;
20+
export const {enableUseRefAccessWarning, enableDeferRootSchedulingToMicrotask} =
21+
dynamicFlags;
2122

2223
// The rest of the flags are static for better dead code elimination.
2324
export const enableDebugTracing = false;

packages/shared/forks/ReactFeatureFlags.native-oss.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export const enableHostSingletons = true;
6969

7070
export const useModernStrictMode = false;
7171
export const enableFizzExternalRuntime = false;
72+
export const enableDeferRootSchedulingToMicrotask = true;
7273

7374
// Flow magic to verify the exports of this file match the original version.
7475
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

packages/shared/forks/ReactFeatureFlags.test-renderer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export const enableHostSingletons = true;
6969

7070
export const useModernStrictMode = false;
7171
export const enableFizzExternalRuntime = false;
72+
export const enableDeferRootSchedulingToMicrotask = true;
7273

7374
// Flow magic to verify the exports of this file match the original version.
7475
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

packages/shared/forks/ReactFeatureFlags.test-renderer.native.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export const enableFloat = true;
6666
export const enableHostSingletons = true;
6767

6868
export const useModernStrictMode = false;
69+
export const enableDeferRootSchedulingToMicrotask = true;
6970

7071
// Flow magic to verify the exports of this file match the original version.
7172
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

packages/shared/forks/ReactFeatureFlags.test-renderer.www.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export const enableHostSingletons = true;
7171

7272
export const useModernStrictMode = false;
7373
export const enableFizzExternalRuntime = false;
74+
export const enableDeferRootSchedulingToMicrotask = true;
7475

7576
// Flow magic to verify the exports of this file match the original version.
7677
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

packages/shared/forks/ReactFeatureFlags.www-dynamic.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export const enableLazyContextPropagation = __VARIANT__;
2323
export const enableUnifiedSyncLane = __VARIANT__;
2424
export const enableTransitionTracing = __VARIANT__;
2525
export const enableCustomElementPropertySupport = __VARIANT__;
26+
export const enableDeferRootSchedulingToMicrotask = __VARIANT__;
2627

2728
// Enable this flag to help with concurrent mode debugging.
2829
// It logs information to the console about React scheduling, rendering, and commit phases.

packages/shared/forks/ReactFeatureFlags.www.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export const {
2727
enableUnifiedSyncLane,
2828
enableTransitionTracing,
2929
enableCustomElementPropertySupport,
30+
enableDeferRootSchedulingToMicrotask,
3031
} = dynamicFeatureFlags;
3132

3233
// On WWW, __EXPERIMENTAL__ is used for a new modern build.

scripts/flow/xplat.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@
99

1010
declare module 'ReactNativeInternalFeatureFlags' {
1111
declare export var enableUseRefAccessWarning: boolean;
12+
declare export var enableDeferRootSchedulingToMicrotask: boolean;
1213
}

0 commit comments

Comments
 (0)