@samitouri / QOS-React-2 / commits / 73e900b0e7

Land enableDiscreteEventMicroTasks (#20954)

Ricky committed Mar 8, 2021 at 16:43 UTC 73e900b0e78c752d1e045a42ddea8175679ea8f7
16 files changed +21 -102
packages/react-dom/src/__tests__/ReactDOMNativeEventHeuristic-test.js
+5 -5
@@ -43,7 +43,7 @@ describe('ReactDOMNativeEventHeuristic-test', () => {
43 }
44
45 // @gate experimental
46 - // @gate enableDiscreteEventMicroTasks && enableNativeEventPriorityInference
46 + // @gate enableNativeEventPriorityInference
47 it('ignores discrete events on a pending removed element', async () => {
48 const disableButtonRef = React.createRef();
49 const submitButtonRef = React.createRef();
@@ -95,7 +95,7 @@ describe('ReactDOMNativeEventHeuristic-test', () => {
95 });
96
97 // @gate experimental
98 - // @gate enableDiscreteEventMicroTasks && enableNativeEventPriorityInference
98 + // @gate enableNativeEventPriorityInference
99 it('ignores discrete events on a pending removed event listener', async () => {
100 const disableButtonRef = React.createRef();
101 const submitButtonRef = React.createRef();
@@ -165,7 +165,7 @@ describe('ReactDOMNativeEventHeuristic-test', () => {
165 });
166
167 // @gate experimental
168 - // @gate enableDiscreteEventMicroTasks && enableNativeEventPriorityInference
168 + // @gate enableNativeEventPriorityInference
169 it('uses the newest discrete events on a pending changed event listener', async () => {
170 const enableButtonRef = React.createRef();
171 const submitButtonRef = React.createRef();
@@ -229,7 +229,7 @@ describe('ReactDOMNativeEventHeuristic-test', () => {
229 });
230
231 // @gate experimental
232 - // @gate enableDiscreteEventMicroTasks && enableNativeEventPriorityInference
232 + // @gate enableNativeEventPriorityInference
233 it('mouse over should be user-blocking but not discrete', async () => {
234 const root = ReactDOM.unstable_createRoot(container);
235
@@ -260,7 +260,7 @@ describe('ReactDOMNativeEventHeuristic-test', () => {
260 });
261
262 // @gate experimental
263 - // @gate enableDiscreteEventMicroTasks && enableNativeEventPriorityInference
263 + // @gate enableNativeEventPriorityInference
264 it('mouse enter should be user-blocking but not discrete', async () => {
265 const root = ReactDOM.unstable_createRoot(container);
266
packages/react-dom/src/client/ReactDOMHostConfig.js
+1 -2
@@ -67,7 +67,6 @@ import {
67 enableCreateEventHandleAPI,
68 enableScopeAPI,
69 enableNewReconciler,
70 - enableDiscreteEventMicroTasks,
70 } from 'shared/ReactFeatureFlags';
71 import {HostComponent, HostText} from 'react-reconciler/src/ReactWorkTags';
72 import {listenToAllSupportedEvents} from '../events/DOMPluginEventSystem';
@@ -404,7 +403,7 @@ export const noTimeout = -1;
403 // -------------------
404 // Microtasks
405 // -------------------
407 -export const supportsMicrotasks = enableDiscreteEventMicroTasks;
406 +export const supportsMicrotasks = true;
407 export const scheduleMicrotask: any =
408 typeof queueMicrotask === 'function'
409 ? queueMicrotask
packages/react-dom/src/events/plugins/__tests__/ChangeEventPlugin-test.js
+4 -11
@@ -728,17 +728,10 @@ describe('ChangeEventPlugin', () => {
728 expect(Scheduler).toHaveYielded([]);
729 expect(input.value).toBe('initial');
730
731 - // Flush callbacks.
732 - // Now the click update has flushed.
733 - if (gate(flags => flags.enableDiscreteEventMicroTasks)) {
734 - // Flush microtask queue.
735 - await null;
736 - expect(Scheduler).toHaveYielded(['render: ']);
737 - expect(input.value).toBe('');
738 - } else {
739 - expect(Scheduler).toFlushAndYield(['render: ']);
740 - expect(input.value).toBe('');
741 - }
731 + // Flush microtask queue.
732 + await null;
733 + expect(Scheduler).toHaveYielded(['render: ']);
734 + expect(input.value).toBe('');
735 });
736
737 // @gate experimental
packages/react-dom/src/events/plugins/__tests__/SimpleEventPlugin-test.js
+9 -18
@@ -470,24 +470,15 @@ describe('SimpleEventPlugin', function() {
470 'High-pri count: 7, Low-pri count: 0',
471 ]);
472
473 - if (gate(flags => flags.enableDiscreteEventMicroTasks)) {
474 - // Flush the microtask queue
475 - await null;
476 -
477 - // At the end, both counters should equal the total number of clicks
478 - expect(Scheduler).toHaveYielded([
479 - 'High-pri count: 8, Low-pri count: 0',
480 - ]);
481 - expect(Scheduler).toFlushAndYield([
482 - 'High-pri count: 8, Low-pri count: 8',
483 - ]);
484 - } else {
485 - // At the end, both counters should equal the total number of clicks
486 - expect(Scheduler).toFlushAndYield([
487 - 'High-pri count: 8, Low-pri count: 0',
488 - 'High-pri count: 8, Low-pri count: 8',
489 - ]);
490 - }
473 + // Flush the microtask queue
474 + await null;
475 +
476 + // At the end, both counters should equal the total number of clicks
477 + expect(Scheduler).toHaveYielded(['High-pri count: 8, Low-pri count: 0']);
478 + expect(Scheduler).toFlushAndYield([
479 + 'High-pri count: 8, Low-pri count: 8',
480 + ]);
481 +
482 expect(button.textContent).toEqual('High-pri count: 8, Low-pri count: 8');
483 });
484 });
packages/react-noop-renderer/src/createReactNoop.js
+2 -5
@@ -27,10 +27,7 @@ import {
27 LegacyRoot,
28 } from 'react-reconciler/src/ReactRootTags';
29
30 -import {
31 - enableNativeEventPriorityInference,
32 - enableDiscreteEventMicroTasks,
33 -} from 'shared/ReactFeatureFlags';
30 +import {enableNativeEventPriorityInference} from 'shared/ReactFeatureFlags';
31 import ReactSharedInternals from 'shared/ReactSharedInternals';
32 import enqueueTask from 'shared/enqueueTask';
33 const {IsSomeRendererActing} = ReactSharedInternals;
@@ -376,7 +373,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
373 cancelTimeout: clearTimeout,
374 noTimeout: -1,
375
379 - supportsMicrotasks: enableDiscreteEventMicroTasks,
376 + supportsMicrotasks: true,
377 scheduleMicrotask:
378 typeof queueMicrotask === 'function'
379 ? queueMicrotask
packages/react-reconciler/src/__tests__/ReactSuspenseWithNoopRenderer-test.js
-50
@@ -3518,56 +3518,6 @@ describe('ReactSuspenseWithNoopRenderer', () => {
3518 );
3519 });
3520
3521 - // @gate enableCache
3522 - // @gate !enableDiscreteEventMicroTasks
3523 - it('regression: empty render at high priority causes update to be dropped', async () => {
3524 - // Reproduces a bug where flushDiscreteUpdates starts a new (empty) render
3525 - // pass which cancels a scheduled timeout and causes the fallback never to
3526 - // be committed.
3527 - function App({text, shouldSuspend}) {
3528 - return (
3529 - <>
3530 - <Text text={text} />
3531 - <Suspense fallback={<Text text="Loading..." />}>
3532 - {shouldSuspend && <AsyncText text="B" />}
3533 - </Suspense>
3534 - </>
3535 - );
3536 - }
3537 -
3538 - const root = ReactNoop.createRoot();
3539 - ReactNoop.discreteUpdates(() => {
3540 - // High pri
3541 - root.render(<App text="A" />);
3542 - });
3543 - // Low pri
3544 - root.render(<App text="A" shouldSuspend={true} />);
3545 -
3546 - expect(Scheduler).toFlushAndYield([
3547 - // Render the high pri update
3548 - 'A',
3549 - // Render the low pri update
3550 - 'A',
3551 - 'Suspend! [B]',
3552 - 'Loading...',
3553 - ]);
3554 - expect(root).toMatchRenderedOutput(<span prop="A" />);
3555 -
3556 - // Triggers erstwhile bug where flushDiscreteUpdates caused an empty render
3557 - // at a previously committed level
3558 - ReactNoop.flushDiscreteUpdates();
3559 -
3560 - // Commit the placeholder
3561 - Scheduler.unstable_advanceTime(2000);
3562 - await advanceTimers(2000);
3563 - expect(root).toMatchRenderedOutput(
3564 - <>
3565 - <span prop="A" />
3566 - <span prop="Loading..." />
3567 - </>,
3568 - );
3569 - });
3570 -
3521 // @gate experimental
3522 // @gate enableCache
3523 it('regression: ping at high priority causes update to be dropped', async () => {
packages/shared/ReactFeatureFlags.js
-2
@@ -150,8 +150,6 @@ export const enableRecursiveCommitTraversal = false;
150
151 export const disableSchedulerTimeoutInWorkLoop = false;
152
153 -export const enableDiscreteEventMicroTasks = false;
154 -
153 export const enableSyncMicroTasks = false;
154
155 export const enableNativeEventPriorityInference = false;
packages/shared/forks/ReactFeatureFlags.native-fb.js
-1
@@ -57,7 +57,6 @@ export const enableUseRefAccessWarning = false;
57
58 export const enableRecursiveCommitTraversal = false;
59 export const disableSchedulerTimeoutInWorkLoop = false;
60 -export const enableDiscreteEventMicroTasks = false;
60 export const enableSyncMicroTasks = false;
61 export const enableNativeEventPriorityInference = false;
62 export const enableLazyContextPropagation = false;
packages/shared/forks/ReactFeatureFlags.native-oss.js
-1
@@ -56,7 +56,6 @@ export const enableUseRefAccessWarning = false;
56
57 export const enableRecursiveCommitTraversal = false;
58 export const disableSchedulerTimeoutInWorkLoop = false;
59 -export const enableDiscreteEventMicroTasks = false;
59 export const enableSyncMicroTasks = false;
60 export const enableNativeEventPriorityInference = false;
61 export const enableLazyContextPropagation = false;
packages/shared/forks/ReactFeatureFlags.test-renderer.js
-1
@@ -56,7 +56,6 @@ export const enableUseRefAccessWarning = false;
56
57 export const enableRecursiveCommitTraversal = false;
58 export const disableSchedulerTimeoutInWorkLoop = false;
59 -export const enableDiscreteEventMicroTasks = false;
59 export const enableSyncMicroTasks = false;
60 export const enableNativeEventPriorityInference = false;
61 export const enableLazyContextPropagation = false;
packages/shared/forks/ReactFeatureFlags.test-renderer.native.js
-1
@@ -56,7 +56,6 @@ export const enableUseRefAccessWarning = false;
56
57 export const enableRecursiveCommitTraversal = false;
58 export const disableSchedulerTimeoutInWorkLoop = false;
59 -export const enableDiscreteEventMicroTasks = false;
59 export const enableSyncMicroTasks = false;
60 export const enableNativeEventPriorityInference = false;
61 export const enableLazyContextPropagation = false;
packages/shared/forks/ReactFeatureFlags.test-renderer.www.js
-1
@@ -56,7 +56,6 @@ export const enableUseRefAccessWarning = false;
56
57 export const enableRecursiveCommitTraversal = false;
58 export const disableSchedulerTimeoutInWorkLoop = false;
59 -export const enableDiscreteEventMicroTasks = false;
59 export const enableSyncMicroTasks = false;
60 export const enableNativeEventPriorityInference = false;
61 export const enableLazyContextPropagation = false;
packages/shared/forks/ReactFeatureFlags.testing.js
-1
@@ -56,7 +56,6 @@ export const enableUseRefAccessWarning = false;
56
57 export const enableRecursiveCommitTraversal = false;
58 export const disableSchedulerTimeoutInWorkLoop = false;
59 -export const enableDiscreteEventMicroTasks = false;
59 export const enableSyncMicroTasks = false;
60 export const enableNativeEventPriorityInference = false;
61 export const enableLazyContextPropagation = false;
packages/shared/forks/ReactFeatureFlags.testing.www.js
-1
@@ -56,7 +56,6 @@ export const enableUseRefAccessWarning = false;
56
57 export const enableRecursiveCommitTraversal = false;
58 export const disableSchedulerTimeoutInWorkLoop = false;
59 -export const enableDiscreteEventMicroTasks = false;
59 export const enableSyncMicroTasks = false;
60 export const enableNativeEventPriorityInference = false;
61 export const enableLazyContextPropagation = false;
packages/shared/forks/ReactFeatureFlags.www-dynamic.js
-1
@@ -55,7 +55,6 @@ export const enableUseRefAccessWarning = __VARIANT__;
55
56 export const enableProfilerNestedUpdateScheduledHook = __VARIANT__;
57 export const disableSchedulerTimeoutInWorkLoop = __VARIANT__;
58 -export const enableDiscreteEventMicroTasks = __VARIANT__;
58 export const enableSyncMicroTasks = __VARIANT__;
59 export const enableNativeEventPriorityInference = __VARIANT__;
60 export const enableLazyContextPropagation = __VARIANT__;
packages/shared/forks/ReactFeatureFlags.www.js
-1
@@ -31,7 +31,6 @@ export const {
31 enableUseRefAccessWarning,
32 disableNativeComponentFrames,
33 disableSchedulerTimeoutInWorkLoop,
34 - enableDiscreteEventMicroTasks,
34 enableSyncMicroTasks,
35 enableNativeEventPriorityInference,
36 enableLazyContextPropagation,