Skip to content

Commit

Permalink
Updates from review
Browse files Browse the repository at this point in the history
  • Loading branch information
rickhanlonii committed Feb 25, 2021
1 parent 4b63f61 commit 4cea1e0
Show file tree
Hide file tree
Showing 17 changed files with 46 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {__interactionsRef} from 'scheduler/tracing';
import {
enableSchedulerTracing,
decoupleUpdatePriorityFromScheduler,
enableSyncMicroTasks,
} from 'shared/ReactFeatureFlags';
import invariant from 'shared/invariant';
import {
Expand Down Expand Up @@ -145,12 +146,13 @@ export function scheduleSyncCallback(callback: SchedulerCallback) {
// the next tick, or earlier if something calls `flushSyncCallbackQueue`.
if (syncQueue === null) {
syncQueue = [callback];
// Flush the queue in the next tick, at the earliest.
// TODO: Figure out how to remove this It's only here as a last resort if we
// forget to explicitly flush.
if (supportsMicrotasks) {
if (enableSyncMicroTasks && supportsMicrotasks) {
// Flush the queue in a microtask.
scheduleMicrotask(flushSyncCallbackQueueImpl);
} else {
// Flush the queue in the next tick, at the earliest.
// TODO: Figure out how to remove this It's only here as a last resort if we
// forget to explicitly flush.
immediateQueueCallbackNode = Scheduler_scheduleCallback(
Scheduler_ImmediatePriority,
flushSyncCallbackQueueImpl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {__interactionsRef} from 'scheduler/tracing';
import {
enableSchedulerTracing,
decoupleUpdatePriorityFromScheduler,
enableSyncMicroTasks,
} from 'shared/ReactFeatureFlags';
import invariant from 'shared/invariant';
import {
Expand Down Expand Up @@ -145,12 +146,13 @@ export function scheduleSyncCallback(callback: SchedulerCallback) {
// the next tick, or earlier if something calls `flushSyncCallbackQueue`.
if (syncQueue === null) {
syncQueue = [callback];
// Flush the queue in the next tick, at the earliest.
// TODO: Figure out how to remove this It's only here as a last resort if we
// forget to explicitly flush.
if (supportsMicrotasks) {
if (enableSyncMicroTasks && supportsMicrotasks) {
// Flush the queue in a microtask.
scheduleMicrotask(flushSyncCallbackQueueImpl);
} else {
// Flush the queue in the next tick, at the earliest.
// TODO: Figure out how to remove this It's only here as a last resort if we
// forget to explicitly flush.
immediateQueueCallbackNode = Scheduler_scheduleCallback(
Scheduler_ImmediatePriority,
flushSyncCallbackQueueImpl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1810,18 +1810,10 @@ describe('ReactHooksWithNoopRenderer', () => {
await act(async () => {
ReactNoop.renderLegacySyncRoot(<Counter count={0} />);

if (gate(flags => flags.enableDiscreteEventMicroTasks)) {
// Flush microtasks.
await null;

// Even in legacy mode, effects are deferred until after paint
expect(Scheduler).toHaveYielded(['Count: (empty)']);
expect(ReactNoop.getChildren()).toEqual([span('Count: (empty)')]);
} else {
// Even in legacy mode, effects are deferred until after paint
expect(Scheduler).toFlushAndYieldThrough(['Count: (empty)']);
expect(ReactNoop.getChildren()).toEqual([span('Count: (empty)')]);
}
// Even in legacy mode, effects are deferred until after paint
ReactNoop.flushSync();
expect(Scheduler).toHaveYielded(['Count: (empty)']);
expect(ReactNoop.getChildren()).toEqual([span('Count: (empty)')]);
});

// effects get forced on exiting act()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1400,6 +1400,10 @@ describe('ReactIncrementalErrorHandling', () => {
'BrokenRenderAndUnmount componentWillUnmount',
]);
expect(ReactNoop.getChildren()).toEqual([]);

expect(() => {
ReactNoop.flushSync();
}).toThrow('One does not simply unmount me.');
});

it('does not interrupt unmounting if detaching a ref throws', () => {
Expand Down
13 changes: 4 additions & 9 deletions packages/react-reconciler/src/__tests__/ReactOffscreen-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,11 @@ describe('ReactOffscreen', () => {
<Text text="Outside" />
</>,
);
if (gate(flags => flags.enableDiscreteEventMicroTasks)) {
// Flush microtasks.
await null;

// Should not defer the hidden tree
expect(Scheduler).toHaveYielded(['A', 'Outside']);
} else {
// Should not defer the hidden tree
expect(Scheduler).toFlushUntilNextPaint(['A', 'Outside']);
}
ReactNoop.flushSync();

// Should not defer the hidden tree
expect(Scheduler).toHaveYielded(['A', 'Outside']);
});
expect(root).toMatchRenderedOutput(
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,17 +569,11 @@ describe(
ReactNoop.render(<App />);
});

if (gate(flags => flags.enableDiscreteEventMicroTasks)) {
await null;

// Because the render expired, React should finish the tree without
// consulting `shouldYield` again
expect(Scheduler).toHaveYielded(['B', 'C']);
} else {
// Because the render expired, React should finish the tree without
// consulting `shouldYield` again
expect(Scheduler).toFlushExpired(['B', 'C']);
}
ReactNoop.flushSync();

// Because the render expired, React should finish the tree without
// consulting `shouldYield` again
expect(Scheduler).toHaveYielded(['B', 'C']);
});
});
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,14 +331,10 @@ describe('ReactSuspensePlaceholder', () => {
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [Loaded]']);
if (gate(flags => flags.enableDiscreteEventMicroTasks)) {
// Flush microtasks
await null;

expect(Scheduler).toHaveYielded(['Loaded']);
} else {
expect(Scheduler).toFlushExpired(['Loaded']);
}

ReactNoop.flushSync();

expect(Scheduler).toHaveYielded(['Loaded']);
expect(ReactNoop).toMatchRenderedOutput('LoadedText');
expect(onRender).toHaveBeenCalledTimes(2);

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

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

if (gate(flags => flags.enableDiscreteEventMicroTasks)) {
// Flush microtasks
await null;
ReactNoop.flushSync();

expect(Scheduler).toHaveYielded(['Loaded']);
} else {
expect(Scheduler).toFlushExpired(['Loaded']);
}
expect(Scheduler).toHaveYielded(['Loaded']);
expect(ReactNoop).toMatchRenderedOutput('LoadedNew');
expect(onRender).toHaveBeenCalledTimes(4);

Expand Down
2 changes: 2 additions & 0 deletions packages/shared/ReactFeatureFlags.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,6 @@ export const enableNonInterruptingNormalPri = false;

export const enableDiscreteEventMicroTasks = false;

export const enableSyncMicroTasks = false;

export const enableNativeEventPriorityInference = false;
1 change: 1 addition & 0 deletions packages/shared/forks/ReactFeatureFlags.native-fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const enableRecursiveCommitTraversal = false;
export const disableSchedulerTimeoutInWorkLoop = false;
export const enableNonInterruptingNormalPri = false;
export const enableDiscreteEventMicroTasks = false;
export const enableSyncMicroTasks = false;
export const enableNativeEventPriorityInference = false;

// Flow magic to verify the exports of this file match the original version.
Expand Down
1 change: 1 addition & 0 deletions packages/shared/forks/ReactFeatureFlags.native-oss.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const enableRecursiveCommitTraversal = false;
export const disableSchedulerTimeoutInWorkLoop = false;
export const enableNonInterruptingNormalPri = false;
export const enableDiscreteEventMicroTasks = false;
export const enableSyncMicroTasks = false;
export const enableNativeEventPriorityInference = false;

// Flow magic to verify the exports of this file match the original version.
Expand Down
1 change: 1 addition & 0 deletions packages/shared/forks/ReactFeatureFlags.test-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const enableRecursiveCommitTraversal = false;
export const disableSchedulerTimeoutInWorkLoop = false;
export const enableNonInterruptingNormalPri = false;
export const enableDiscreteEventMicroTasks = false;
export const enableSyncMicroTasks = false;
export const enableNativeEventPriorityInference = false;

// Flow magic to verify the exports of this file match the original version.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const enableRecursiveCommitTraversal = false;
export const disableSchedulerTimeoutInWorkLoop = false;
export const enableNonInterruptingNormalPri = false;
export const enableDiscreteEventMicroTasks = false;
export const enableSyncMicroTasks = false;
export const enableNativeEventPriorityInference = false;

// Flow magic to verify the exports of this file match the original version.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const enableRecursiveCommitTraversal = false;
export const disableSchedulerTimeoutInWorkLoop = false;
export const enableNonInterruptingNormalPri = false;
export const enableDiscreteEventMicroTasks = false;
export const enableSyncMicroTasks = false;
export const enableNativeEventPriorityInference = false;

// Flow magic to verify the exports of this file match the original version.
Expand Down
1 change: 1 addition & 0 deletions packages/shared/forks/ReactFeatureFlags.testing.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const enableRecursiveCommitTraversal = false;
export const disableSchedulerTimeoutInWorkLoop = false;
export const enableNonInterruptingNormalPri = false;
export const enableDiscreteEventMicroTasks = false;
export const enableSyncMicroTasks = false;
export const enableNativeEventPriorityInference = false;

// Flow magic to verify the exports of this file match the original version.
Expand Down
1 change: 1 addition & 0 deletions packages/shared/forks/ReactFeatureFlags.testing.www.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const enableRecursiveCommitTraversal = false;
export const disableSchedulerTimeoutInWorkLoop = false;
export const enableNonInterruptingNormalPri = false;
export const enableDiscreteEventMicroTasks = false;
export const enableSyncMicroTasks = false;
export const enableNativeEventPriorityInference = false;

// Flow magic to verify the exports of this file match the original version.
Expand Down
1 change: 1 addition & 0 deletions packages/shared/forks/ReactFeatureFlags.www-dynamic.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ export const enableProfilerNestedUpdateScheduledHook = __VARIANT__;
export const disableSchedulerTimeoutInWorkLoop = __VARIANT__;
export const enableNonInterruptingNormalPri = __VARIANT__;
export const enableDiscreteEventMicroTasks = __VARIANT__;
export const enableSyncMicroTasks = __VARIANT__;
export const enableNativeEventPriorityInference = __VARIANT__;
1 change: 1 addition & 0 deletions packages/shared/forks/ReactFeatureFlags.www.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const {
disableSchedulerTimeoutInWorkLoop,
enableNonInterruptingNormalPri,
enableDiscreteEventMicroTasks,
enableSyncMicroTasks,
enableNativeEventPriorityInference,
} = dynamicFeatureFlags;

Expand Down

0 comments on commit 4cea1e0

Please sign in to comment.