Skip to content

Commit 4cea1e0

Browse files
committed
Updates from review
1 parent 4b63f61 commit 4cea1e0

17 files changed

+46
-55
lines changed

packages/react-reconciler/src/SchedulerWithReactIntegration.new.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {__interactionsRef} from 'scheduler/tracing';
1616
import {
1717
enableSchedulerTracing,
1818
decoupleUpdatePriorityFromScheduler,
19+
enableSyncMicroTasks,
1920
} from 'shared/ReactFeatureFlags';
2021
import invariant from 'shared/invariant';
2122
import {
@@ -145,12 +146,13 @@ export function scheduleSyncCallback(callback: SchedulerCallback) {
145146
// the next tick, or earlier if something calls `flushSyncCallbackQueue`.
146147
if (syncQueue === null) {
147148
syncQueue = [callback];
148-
// Flush the queue in the next tick, at the earliest.
149-
// TODO: Figure out how to remove this It's only here as a last resort if we
150-
// forget to explicitly flush.
151-
if (supportsMicrotasks) {
149+
if (enableSyncMicroTasks && supportsMicrotasks) {
150+
// Flush the queue in a microtask.
152151
scheduleMicrotask(flushSyncCallbackQueueImpl);
153152
} else {
153+
// Flush the queue in the next tick, at the earliest.
154+
// TODO: Figure out how to remove this It's only here as a last resort if we
155+
// forget to explicitly flush.
154156
immediateQueueCallbackNode = Scheduler_scheduleCallback(
155157
Scheduler_ImmediatePriority,
156158
flushSyncCallbackQueueImpl,

packages/react-reconciler/src/SchedulerWithReactIntegration.old.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {__interactionsRef} from 'scheduler/tracing';
1616
import {
1717
enableSchedulerTracing,
1818
decoupleUpdatePriorityFromScheduler,
19+
enableSyncMicroTasks,
1920
} from 'shared/ReactFeatureFlags';
2021
import invariant from 'shared/invariant';
2122
import {
@@ -145,12 +146,13 @@ export function scheduleSyncCallback(callback: SchedulerCallback) {
145146
// the next tick, or earlier if something calls `flushSyncCallbackQueue`.
146147
if (syncQueue === null) {
147148
syncQueue = [callback];
148-
// Flush the queue in the next tick, at the earliest.
149-
// TODO: Figure out how to remove this It's only here as a last resort if we
150-
// forget to explicitly flush.
151-
if (supportsMicrotasks) {
149+
if (enableSyncMicroTasks && supportsMicrotasks) {
150+
// Flush the queue in a microtask.
152151
scheduleMicrotask(flushSyncCallbackQueueImpl);
153152
} else {
153+
// Flush the queue in the next tick, at the earliest.
154+
// TODO: Figure out how to remove this It's only here as a last resort if we
155+
// forget to explicitly flush.
154156
immediateQueueCallbackNode = Scheduler_scheduleCallback(
155157
Scheduler_ImmediatePriority,
156158
flushSyncCallbackQueueImpl,

packages/react-reconciler/src/__tests__/ReactHooksWithNoopRenderer-test.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1810,18 +1810,10 @@ describe('ReactHooksWithNoopRenderer', () => {
18101810
await act(async () => {
18111811
ReactNoop.renderLegacySyncRoot(<Counter count={0} />);
18121812

1813-
if (gate(flags => flags.enableDiscreteEventMicroTasks)) {
1814-
// Flush microtasks.
1815-
await null;
1816-
1817-
// Even in legacy mode, effects are deferred until after paint
1818-
expect(Scheduler).toHaveYielded(['Count: (empty)']);
1819-
expect(ReactNoop.getChildren()).toEqual([span('Count: (empty)')]);
1820-
} else {
1821-
// Even in legacy mode, effects are deferred until after paint
1822-
expect(Scheduler).toFlushAndYieldThrough(['Count: (empty)']);
1823-
expect(ReactNoop.getChildren()).toEqual([span('Count: (empty)')]);
1824-
}
1813+
// Even in legacy mode, effects are deferred until after paint
1814+
ReactNoop.flushSync();
1815+
expect(Scheduler).toHaveYielded(['Count: (empty)']);
1816+
expect(ReactNoop.getChildren()).toEqual([span('Count: (empty)')]);
18251817
});
18261818

18271819
// effects get forced on exiting act()

packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.internal.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,6 +1400,10 @@ describe('ReactIncrementalErrorHandling', () => {
14001400
'BrokenRenderAndUnmount componentWillUnmount',
14011401
]);
14021402
expect(ReactNoop.getChildren()).toEqual([]);
1403+
1404+
expect(() => {
1405+
ReactNoop.flushSync();
1406+
}).toThrow('One does not simply unmount me.');
14031407
});
14041408

14051409
it('does not interrupt unmounting if detaching a ref throws', () => {

packages/react-reconciler/src/__tests__/ReactOffscreen-test.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,11 @@ describe('ReactOffscreen', () => {
9898
<Text text="Outside" />
9999
</>,
100100
);
101-
if (gate(flags => flags.enableDiscreteEventMicroTasks)) {
102-
// Flush microtasks.
103-
await null;
104101

105-
// Should not defer the hidden tree
106-
expect(Scheduler).toHaveYielded(['A', 'Outside']);
107-
} else {
108-
// Should not defer the hidden tree
109-
expect(Scheduler).toFlushUntilNextPaint(['A', 'Outside']);
110-
}
102+
ReactNoop.flushSync();
103+
104+
// Should not defer the hidden tree
105+
expect(Scheduler).toHaveYielded(['A', 'Outside']);
111106
});
112107
expect(root).toMatchRenderedOutput(
113108
<>

packages/react-reconciler/src/__tests__/ReactSchedulerIntegration-test.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -569,17 +569,11 @@ describe(
569569
ReactNoop.render(<App />);
570570
});
571571

572-
if (gate(flags => flags.enableDiscreteEventMicroTasks)) {
573-
await null;
574-
575-
// Because the render expired, React should finish the tree without
576-
// consulting `shouldYield` again
577-
expect(Scheduler).toHaveYielded(['B', 'C']);
578-
} else {
579-
// Because the render expired, React should finish the tree without
580-
// consulting `shouldYield` again
581-
expect(Scheduler).toFlushExpired(['B', 'C']);
582-
}
572+
ReactNoop.flushSync();
573+
574+
// Because the render expired, React should finish the tree without
575+
// consulting `shouldYield` again
576+
expect(Scheduler).toHaveYielded(['B', 'C']);
583577
});
584578
});
585579
},

packages/react-reconciler/src/__tests__/ReactSuspensePlaceholder-test.internal.js

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -331,14 +331,10 @@ describe('ReactSuspensePlaceholder', () => {
331331
jest.advanceTimersByTime(1000);
332332

333333
expect(Scheduler).toHaveYielded(['Promise resolved [Loaded]']);
334-
if (gate(flags => flags.enableDiscreteEventMicroTasks)) {
335-
// Flush microtasks
336-
await null;
337-
338-
expect(Scheduler).toHaveYielded(['Loaded']);
339-
} else {
340-
expect(Scheduler).toFlushExpired(['Loaded']);
341-
}
334+
335+
ReactNoop.flushSync();
336+
337+
expect(Scheduler).toHaveYielded(['Loaded']);
342338
expect(ReactNoop).toMatchRenderedOutput('LoadedText');
343339
expect(onRender).toHaveBeenCalledTimes(2);
344340

@@ -435,14 +431,9 @@ describe('ReactSuspensePlaceholder', () => {
435431

436432
expect(Scheduler).toHaveYielded(['Promise resolved [Loaded]']);
437433

438-
if (gate(flags => flags.enableDiscreteEventMicroTasks)) {
439-
// Flush microtasks
440-
await null;
434+
ReactNoop.flushSync();
441435

442-
expect(Scheduler).toHaveYielded(['Loaded']);
443-
} else {
444-
expect(Scheduler).toFlushExpired(['Loaded']);
445-
}
436+
expect(Scheduler).toHaveYielded(['Loaded']);
446437
expect(ReactNoop).toMatchRenderedOutput('LoadedNew');
447438
expect(onRender).toHaveBeenCalledTimes(4);
448439

packages/shared/ReactFeatureFlags.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,6 @@ export const enableNonInterruptingNormalPri = false;
151151

152152
export const enableDiscreteEventMicroTasks = false;
153153

154+
export const enableSyncMicroTasks = false;
155+
154156
export const enableNativeEventPriorityInference = false;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export const enableRecursiveCommitTraversal = false;
5959
export const disableSchedulerTimeoutInWorkLoop = false;
6060
export const enableNonInterruptingNormalPri = false;
6161
export const enableDiscreteEventMicroTasks = false;
62+
export const enableSyncMicroTasks = false;
6263
export const enableNativeEventPriorityInference = false;
6364

6465
// Flow magic to verify the exports of this file match the original version.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export const enableRecursiveCommitTraversal = false;
5858
export const disableSchedulerTimeoutInWorkLoop = false;
5959
export const enableNonInterruptingNormalPri = false;
6060
export const enableDiscreteEventMicroTasks = false;
61+
export const enableSyncMicroTasks = false;
6162
export const enableNativeEventPriorityInference = false;
6263

6364
// Flow magic to verify the exports of this file match the original version.

0 commit comments

Comments
 (0)