Land enableDiscreteEventMicroTasks (#20954)

This commit is contained in:
Ricky
2021-03-08 16:43:44 -05:00
committed by GitHub
parent a3f30fed29
commit 73e900b0e7
16 changed files with 20 additions and 101 deletions
@@ -43,7 +43,7 @@ describe('ReactDOMNativeEventHeuristic-test', () => {
}
// @gate experimental
// @gate enableDiscreteEventMicroTasks && enableNativeEventPriorityInference
// @gate enableNativeEventPriorityInference
it('ignores discrete events on a pending removed element', async () => {
const disableButtonRef = React.createRef();
const submitButtonRef = React.createRef();
@@ -95,7 +95,7 @@ describe('ReactDOMNativeEventHeuristic-test', () => {
});
// @gate experimental
// @gate enableDiscreteEventMicroTasks && enableNativeEventPriorityInference
// @gate enableNativeEventPriorityInference
it('ignores discrete events on a pending removed event listener', async () => {
const disableButtonRef = React.createRef();
const submitButtonRef = React.createRef();
@@ -165,7 +165,7 @@ describe('ReactDOMNativeEventHeuristic-test', () => {
});
// @gate experimental
// @gate enableDiscreteEventMicroTasks && enableNativeEventPriorityInference
// @gate enableNativeEventPriorityInference
it('uses the newest discrete events on a pending changed event listener', async () => {
const enableButtonRef = React.createRef();
const submitButtonRef = React.createRef();
@@ -229,7 +229,7 @@ describe('ReactDOMNativeEventHeuristic-test', () => {
});
// @gate experimental
// @gate enableDiscreteEventMicroTasks && enableNativeEventPriorityInference
// @gate enableNativeEventPriorityInference
it('mouse over should be user-blocking but not discrete', async () => {
const root = ReactDOM.unstable_createRoot(container);
@@ -260,7 +260,7 @@ describe('ReactDOMNativeEventHeuristic-test', () => {
});
// @gate experimental
// @gate enableDiscreteEventMicroTasks && enableNativeEventPriorityInference
// @gate enableNativeEventPriorityInference
it('mouse enter should be user-blocking but not discrete', async () => {
const root = ReactDOM.unstable_createRoot(container);
+1 -2
View File
@@ -67,7 +67,6 @@ import {
enableCreateEventHandleAPI,
enableScopeAPI,
enableNewReconciler,
enableDiscreteEventMicroTasks,
} from 'shared/ReactFeatureFlags';
import {HostComponent, HostText} from 'react-reconciler/src/ReactWorkTags';
import {listenToAllSupportedEvents} from '../events/DOMPluginEventSystem';
@@ -404,7 +403,7 @@ export const noTimeout = -1;
// -------------------
// Microtasks
// -------------------
export const supportsMicrotasks = enableDiscreteEventMicroTasks;
export const supportsMicrotasks = true;
export const scheduleMicrotask: any =
typeof queueMicrotask === 'function'
? queueMicrotask
@@ -728,17 +728,10 @@ describe('ChangeEventPlugin', () => {
expect(Scheduler).toHaveYielded([]);
expect(input.value).toBe('initial');
// Flush callbacks.
// Now the click update has flushed.
if (gate(flags => flags.enableDiscreteEventMicroTasks)) {
// Flush microtask queue.
await null;
expect(Scheduler).toHaveYielded(['render: ']);
expect(input.value).toBe('');
} else {
expect(Scheduler).toFlushAndYield(['render: ']);
expect(input.value).toBe('');
}
// Flush microtask queue.
await null;
expect(Scheduler).toHaveYielded(['render: ']);
expect(input.value).toBe('');
});
// @gate experimental
@@ -470,24 +470,15 @@ describe('SimpleEventPlugin', function() {
'High-pri count: 7, Low-pri count: 0',
]);
if (gate(flags => flags.enableDiscreteEventMicroTasks)) {
// Flush the microtask queue
await null;
// Flush the microtask queue
await null;
// At the end, both counters should equal the total number of clicks
expect(Scheduler).toHaveYielded(['High-pri count: 8, Low-pri count: 0']);
expect(Scheduler).toFlushAndYield([
'High-pri count: 8, Low-pri count: 8',
]);
// At the end, both counters should equal the total number of clicks
expect(Scheduler).toHaveYielded([
'High-pri count: 8, Low-pri count: 0',
]);
expect(Scheduler).toFlushAndYield([
'High-pri count: 8, Low-pri count: 8',
]);
} else {
// At the end, both counters should equal the total number of clicks
expect(Scheduler).toFlushAndYield([
'High-pri count: 8, Low-pri count: 0',
'High-pri count: 8, Low-pri count: 8',
]);
}
expect(button.textContent).toEqual('High-pri count: 8, Low-pri count: 8');
});
});
+2 -5
View File
@@ -27,10 +27,7 @@ import {
LegacyRoot,
} from 'react-reconciler/src/ReactRootTags';
import {
enableNativeEventPriorityInference,
enableDiscreteEventMicroTasks,
} from 'shared/ReactFeatureFlags';
import {enableNativeEventPriorityInference} from 'shared/ReactFeatureFlags';
import ReactSharedInternals from 'shared/ReactSharedInternals';
import enqueueTask from 'shared/enqueueTask';
const {IsSomeRendererActing} = ReactSharedInternals;
@@ -376,7 +373,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
cancelTimeout: clearTimeout,
noTimeout: -1,
supportsMicrotasks: enableDiscreteEventMicroTasks,
supportsMicrotasks: true,
scheduleMicrotask:
typeof queueMicrotask === 'function'
? queueMicrotask
@@ -3518,56 +3518,6 @@ describe('ReactSuspenseWithNoopRenderer', () => {
);
});
// @gate enableCache
// @gate !enableDiscreteEventMicroTasks
it('regression: empty render at high priority causes update to be dropped', async () => {
// Reproduces a bug where flushDiscreteUpdates starts a new (empty) render
// pass which cancels a scheduled timeout and causes the fallback never to
// be committed.
function App({text, shouldSuspend}) {
return (
<>
<Text text={text} />
<Suspense fallback={<Text text="Loading..." />}>
{shouldSuspend && <AsyncText text="B" />}
</Suspense>
</>
);
}
const root = ReactNoop.createRoot();
ReactNoop.discreteUpdates(() => {
// High pri
root.render(<App text="A" />);
});
// Low pri
root.render(<App text="A" shouldSuspend={true} />);
expect(Scheduler).toFlushAndYield([
// Render the high pri update
'A',
// Render the low pri update
'A',
'Suspend! [B]',
'Loading...',
]);
expect(root).toMatchRenderedOutput(<span prop="A" />);
// Triggers erstwhile bug where flushDiscreteUpdates caused an empty render
// at a previously committed level
ReactNoop.flushDiscreteUpdates();
// Commit the placeholder
Scheduler.unstable_advanceTime(2000);
await advanceTimers(2000);
expect(root).toMatchRenderedOutput(
<>
<span prop="A" />
<span prop="Loading..." />
</>,
);
});
// @gate experimental
// @gate enableCache
it('regression: ping at high priority causes update to be dropped', async () => {
-2
View File
@@ -150,8 +150,6 @@ export const enableRecursiveCommitTraversal = false;
export const disableSchedulerTimeoutInWorkLoop = false;
export const enableDiscreteEventMicroTasks = false;
export const enableSyncMicroTasks = false;
export const enableNativeEventPriorityInference = false;
@@ -57,7 +57,6 @@ export const enableUseRefAccessWarning = false;
export const enableRecursiveCommitTraversal = false;
export const disableSchedulerTimeoutInWorkLoop = false;
export const enableDiscreteEventMicroTasks = false;
export const enableSyncMicroTasks = false;
export const enableNativeEventPriorityInference = false;
export const enableLazyContextPropagation = false;
@@ -56,7 +56,6 @@ export const enableUseRefAccessWarning = false;
export const enableRecursiveCommitTraversal = false;
export const disableSchedulerTimeoutInWorkLoop = false;
export const enableDiscreteEventMicroTasks = false;
export const enableSyncMicroTasks = false;
export const enableNativeEventPriorityInference = false;
export const enableLazyContextPropagation = false;
@@ -56,7 +56,6 @@ export const enableUseRefAccessWarning = false;
export const enableRecursiveCommitTraversal = false;
export const disableSchedulerTimeoutInWorkLoop = false;
export const enableDiscreteEventMicroTasks = false;
export const enableSyncMicroTasks = false;
export const enableNativeEventPriorityInference = false;
export const enableLazyContextPropagation = false;
@@ -56,7 +56,6 @@ export const enableUseRefAccessWarning = false;
export const enableRecursiveCommitTraversal = false;
export const disableSchedulerTimeoutInWorkLoop = false;
export const enableDiscreteEventMicroTasks = false;
export const enableSyncMicroTasks = false;
export const enableNativeEventPriorityInference = false;
export const enableLazyContextPropagation = false;
@@ -56,7 +56,6 @@ export const enableUseRefAccessWarning = false;
export const enableRecursiveCommitTraversal = false;
export const disableSchedulerTimeoutInWorkLoop = false;
export const enableDiscreteEventMicroTasks = false;
export const enableSyncMicroTasks = false;
export const enableNativeEventPriorityInference = false;
export const enableLazyContextPropagation = false;
@@ -56,7 +56,6 @@ export const enableUseRefAccessWarning = false;
export const enableRecursiveCommitTraversal = false;
export const disableSchedulerTimeoutInWorkLoop = false;
export const enableDiscreteEventMicroTasks = false;
export const enableSyncMicroTasks = false;
export const enableNativeEventPriorityInference = false;
export const enableLazyContextPropagation = false;
@@ -56,7 +56,6 @@ export const enableUseRefAccessWarning = false;
export const enableRecursiveCommitTraversal = false;
export const disableSchedulerTimeoutInWorkLoop = false;
export const enableDiscreteEventMicroTasks = false;
export const enableSyncMicroTasks = false;
export const enableNativeEventPriorityInference = false;
export const enableLazyContextPropagation = false;
@@ -55,7 +55,6 @@ export const enableUseRefAccessWarning = __VARIANT__;
export const enableProfilerNestedUpdateScheduledHook = __VARIANT__;
export const disableSchedulerTimeoutInWorkLoop = __VARIANT__;
export const enableDiscreteEventMicroTasks = __VARIANT__;
export const enableSyncMicroTasks = __VARIANT__;
export const enableNativeEventPriorityInference = __VARIANT__;
export const enableLazyContextPropagation = __VARIANT__;
@@ -31,7 +31,6 @@ export const {
enableUseRefAccessWarning,
disableNativeComponentFrames,
disableSchedulerTimeoutInWorkLoop,
enableDiscreteEventMicroTasks,
enableSyncMicroTasks,
enableNativeEventPriorityInference,
enableLazyContextPropagation,