Skip to content

Commit

Permalink
Land enableDiscreteEventMicroTasks (#20954)
Browse files Browse the repository at this point in the history
  • Loading branch information
rickhanlonii committed Mar 8, 2021
1 parent a3f30fe commit 73e900b
Show file tree
Hide file tree
Showing 16 changed files with 21 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
3 changes: 1 addition & 2 deletions packages/react-dom/src/client/ReactDOMHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

// 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',
]);
}
// 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',
]);

expect(button.textContent).toEqual('High-pri count: 8, Low-pri count: 8');
});
});
Expand Down
7 changes: 2 additions & 5 deletions packages/react-noop-renderer/src/createReactNoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -376,7 +373,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
cancelTimeout: clearTimeout,
noTimeout: -1,

supportsMicrotasks: enableDiscreteEventMicroTasks,
supportsMicrotasks: true,
scheduleMicrotask:
typeof queueMicrotask === 'function'
? queueMicrotask
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
2 changes: 0 additions & 2 deletions packages/shared/ReactFeatureFlags.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ export const enableRecursiveCommitTraversal = false;

export const disableSchedulerTimeoutInWorkLoop = false;

export const enableDiscreteEventMicroTasks = false;

export const enableSyncMicroTasks = false;

export const enableNativeEventPriorityInference = false;
Expand Down
1 change: 0 additions & 1 deletion packages/shared/forks/ReactFeatureFlags.native-fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion packages/shared/forks/ReactFeatureFlags.native-oss.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion packages/shared/forks/ReactFeatureFlags.test-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion packages/shared/forks/ReactFeatureFlags.testing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion packages/shared/forks/ReactFeatureFlags.testing.www.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion packages/shared/forks/ReactFeatureFlags.www-dynamic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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__;
1 change: 0 additions & 1 deletion packages/shared/forks/ReactFeatureFlags.www.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export const {
enableUseRefAccessWarning,
disableNativeComponentFrames,
disableSchedulerTimeoutInWorkLoop,
enableDiscreteEventMicroTasks,
enableSyncMicroTasks,
enableNativeEventPriorityInference,
enableLazyContextPropagation,
Expand Down

0 comments on commit 73e900b

Please sign in to comment.