Skip to content

Commit

Permalink
Remove flushExpired
Browse files Browse the repository at this point in the history
  • Loading branch information
rickhanlonii committed Mar 22, 2021
1 parent 1fafac0 commit 9377006
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ describe('ReactSuspense', () => {

await LazyClass;

expect(Scheduler).toFlushExpired(['Hi', 'Did mount: Hi']);
expect(Scheduler).toFlushUntilNextPaint(['Hi', 'Did mount: Hi']);
expect(root).toMatchRenderedOutput('Hi');
});

Expand Down Expand Up @@ -729,7 +729,7 @@ describe('ReactSuspense', () => {
jest.advanceTimersByTime(100);

expect(Scheduler).toHaveYielded(['Promise resolved [B:1]']);
expect(Scheduler).toFlushExpired([
expect(Scheduler).toFlushUntilNextPaint([
'B:1',
'Unmount [Loading...]',
// Should be a mount, not an update
Expand All @@ -748,7 +748,7 @@ describe('ReactSuspense', () => {
jest.advanceTimersByTime(100);

expect(Scheduler).toHaveYielded(['Promise resolved [B:2]']);
expect(Scheduler).toFlushExpired([
expect(Scheduler).toFlushUntilNextPaint([
'B:2',
'Unmount [Loading...]',
'Update [B:2]',
Expand Down Expand Up @@ -786,7 +786,7 @@ describe('ReactSuspense', () => {
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [A]']);
expect(Scheduler).toFlushExpired(['A']);
expect(Scheduler).toFlushUntilNextPaint(['A']);
expect(root).toMatchRenderedOutput('Stateful: 1A');

root.update(<App text="B" />);
Expand All @@ -804,7 +804,7 @@ describe('ReactSuspense', () => {
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [B]']);
expect(Scheduler).toFlushExpired(['B']);
expect(Scheduler).toFlushUntilNextPaint(['B']);
expect(root).toMatchRenderedOutput('Stateful: 2B');
});

Expand Down Expand Up @@ -846,7 +846,7 @@ describe('ReactSuspense', () => {
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [A]']);
expect(Scheduler).toFlushExpired(['A']);
expect(Scheduler).toFlushUntilNextPaint(['A']);
expect(root).toMatchRenderedOutput('Stateful: 1A');

root.update(<App text="B" />);
Expand All @@ -871,7 +871,7 @@ describe('ReactSuspense', () => {
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [B]']);
expect(Scheduler).toFlushExpired(['B']);
expect(Scheduler).toFlushUntilNextPaint(['B']);
expect(root).toMatchRenderedOutput('Stateful: 2B');
});

Expand Down Expand Up @@ -951,7 +951,7 @@ describe('ReactSuspense', () => {
jest.advanceTimersByTime(500);

expect(Scheduler).toHaveYielded(['Promise resolved [A]']);
expect(Scheduler).toFlushExpired(['A', 'Did commit: A']);
expect(Scheduler).toFlushUntilNextPaint(['A', 'Did commit: A']);
});

it('retries when an update is scheduled on a timed out tree', () => {
Expand Down Expand Up @@ -1038,7 +1038,7 @@ describe('ReactSuspense', () => {
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [Child 1]']);
expect(Scheduler).toFlushExpired([
expect(Scheduler).toFlushUntilNextPaint([
'Child 1',
'Suspend! [Child 2]',
'Suspend! [Child 3]',
Expand All @@ -1047,12 +1047,15 @@ describe('ReactSuspense', () => {
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [Child 2]']);
expect(Scheduler).toFlushExpired(['Child 2', 'Suspend! [Child 3]']);
expect(Scheduler).toFlushUntilNextPaint([
'Child 2',
'Suspend! [Child 3]',
]);

jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [Child 3]']);
expect(Scheduler).toFlushExpired(['Child 3']);
expect(Scheduler).toFlushUntilNextPaint(['Child 3']);
expect(root).toMatchRenderedOutput(
['Child 1', 'Child 2', 'Child 3'].join(''),
);
Expand Down Expand Up @@ -1113,7 +1116,7 @@ describe('ReactSuspense', () => {
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [Tab: 0]']);
expect(Scheduler).toFlushExpired(['Tab: 0']);
expect(Scheduler).toFlushUntilNextPaint(['Tab: 0']);
expect(root).toMatchRenderedOutput('Tab: 0 + sibling');

act(() => setTab(1));
Expand All @@ -1126,7 +1129,7 @@ describe('ReactSuspense', () => {
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [Tab: 1]']);
expect(Scheduler).toFlushExpired(['Tab: 1']);
expect(Scheduler).toFlushUntilNextPaint(['Tab: 1']);
expect(root).toMatchRenderedOutput('Tab: 1 + sibling');

act(() => setTab(2));
Expand All @@ -1139,7 +1142,7 @@ describe('ReactSuspense', () => {
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [Tab: 2]']);
expect(Scheduler).toFlushExpired(['Tab: 2']);
expect(Scheduler).toFlushUntilNextPaint(['Tab: 2']);
expect(root).toMatchRenderedOutput('Tab: 2 + sibling');
});

Expand Down Expand Up @@ -1177,7 +1180,7 @@ describe('ReactSuspense', () => {
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [A:0]']);
expect(Scheduler).toFlushExpired(['A:0']);
expect(Scheduler).toFlushUntilNextPaint(['A:0']);
expect(root).toMatchRenderedOutput('A:0');

act(() => setStep(1));
Expand Down Expand Up @@ -1215,7 +1218,7 @@ describe('ReactSuspense', () => {
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [A]']);
expect(Scheduler).toFlushExpired([
expect(Scheduler).toFlushUntilNextPaint([
'A',
// The promises for B and C have now been thrown twice
'Suspend! [B]',
Expand All @@ -1226,7 +1229,7 @@ describe('ReactSuspense', () => {
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [B]']);
expect(Scheduler).toFlushExpired([
expect(Scheduler).toFlushUntilNextPaint([
// Even though the promise for B was thrown twice, we should only
// re-render once.
'B',
Expand All @@ -1238,7 +1241,7 @@ describe('ReactSuspense', () => {
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [C]']);
expect(Scheduler).toFlushExpired([
expect(Scheduler).toFlushUntilNextPaint([
// Even though the promise for C was thrown three times, we should only
// re-render once.
'C',
Expand Down Expand Up @@ -1280,7 +1283,7 @@ describe('ReactSuspense', () => {
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [A]']);
expect(Scheduler).toFlushExpired([
expect(Scheduler).toFlushUntilNextPaint([
'A',
// The promises for B and C have now been thrown twice
'Suspend! [B]',
Expand All @@ -1291,7 +1294,7 @@ describe('ReactSuspense', () => {
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [B]']);
expect(Scheduler).toFlushExpired([
expect(Scheduler).toFlushUntilNextPaint([
// Even though the promise for B was thrown twice, we should only
// re-render once.
'B',
Expand Down Expand Up @@ -1393,15 +1396,15 @@ describe('ReactSuspense', () => {
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [default]']);
expect(Scheduler).toFlushExpired(['default']);
expect(Scheduler).toFlushUntilNextPaint(['default']);
expect(root).toMatchRenderedOutput('default');

act(() => setValue('new value'));
expect(Scheduler).toHaveYielded(['Suspend! [new value]', 'Loading...']);
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [new value]']);
expect(Scheduler).toFlushExpired(['new value']);
expect(Scheduler).toFlushUntilNextPaint(['new value']);
expect(root).toMatchRenderedOutput('new value');
});

Expand Down Expand Up @@ -1450,15 +1453,15 @@ describe('ReactSuspense', () => {
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [default]']);
expect(Scheduler).toFlushExpired(['default']);
expect(Scheduler).toFlushUntilNextPaint(['default']);
expect(root).toMatchRenderedOutput('default');

act(() => setValue('new value'));
expect(Scheduler).toHaveYielded(['Suspend! [new value]', 'Loading...']);
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [new value]']);
expect(Scheduler).toFlushExpired(['new value']);
expect(Scheduler).toFlushUntilNextPaint(['new value']);
expect(root).toMatchRenderedOutput('new value');
});

Expand Down Expand Up @@ -1506,15 +1509,15 @@ describe('ReactSuspense', () => {
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [default]']);
expect(Scheduler).toFlushExpired(['default']);
expect(Scheduler).toFlushUntilNextPaint(['default']);
expect(root).toMatchRenderedOutput('default');

act(() => setValue('new value'));
expect(Scheduler).toHaveYielded(['Suspend! [new value]', 'Loading...']);
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [new value]']);
expect(Scheduler).toFlushExpired(['new value']);
expect(Scheduler).toFlushUntilNextPaint(['new value']);
expect(root).toMatchRenderedOutput('new value');
});

Expand Down Expand Up @@ -1558,15 +1561,15 @@ describe('ReactSuspense', () => {
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [default]']);
expect(Scheduler).toFlushExpired(['default']);
expect(Scheduler).toFlushUntilNextPaint(['default']);
expect(root).toMatchRenderedOutput('default');

act(() => setValue('new value'));
expect(Scheduler).toHaveYielded(['Suspend! [new value]', 'Loading...']);
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [new value]']);
expect(Scheduler).toFlushExpired(['new value']);
expect(Scheduler).toFlushUntilNextPaint(['new value']);
expect(root).toMatchRenderedOutput('new value');
});
});
Expand Down
6 changes: 3 additions & 3 deletions packages/react/src/__tests__/ReactProfiler-test.internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -4306,7 +4306,7 @@ describe('Profiler', () => {
await resourcePromise;

expect(Scheduler).toHaveYielded(['Promise resolved [loaded]']);
expect(Scheduler).toFlushExpired([
expect(Scheduler).toFlushUntilNextPaint([
'onPostCommit',
'AsyncText [loaded]',
]);
Expand Down Expand Up @@ -4370,7 +4370,7 @@ describe('Profiler', () => {
await resourcePromise;

expect(Scheduler).toHaveYielded(['Promise resolved [loaded]']);
expect(Scheduler).toFlushExpired(['onPostCommit', 'render']);
expect(Scheduler).toFlushUntilNextPaint(['onPostCommit', 'render']);

expect(onInteractionScheduledWorkCompleted).not.toHaveBeenCalled();

Expand Down Expand Up @@ -4575,7 +4575,7 @@ describe('Profiler', () => {
await originalPromise;

expect(Scheduler).toHaveYielded(['Promise resolved [loaded]']);
expect(Scheduler).toFlushExpired(['AsyncText [loaded]']);
expect(Scheduler).toFlushUntilNextPaint(['AsyncText [loaded]']);
expect(renderer.toJSON()).toEqual(['loaded', 'updated']);
expect(Scheduler).toFlushAndYield(['onPostCommit']);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ describe('ReactProfiler DevTools integration', () => {
root.update(<Text text="B" />);

// Update B should not instantly expire.
expect(Scheduler).toFlushExpired([]);
expect(Scheduler).toFlushAndYieldThrough([]);

expect(Scheduler).toFlushAndYield(['B']);
expect(root).toMatchRenderedOutput('B');
Expand Down
51 changes: 6 additions & 45 deletions packages/scheduler/src/__tests__/SchedulerMock-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ describe('Scheduler', () => {

// Advance by just a bit more to expire the user blocking callbacks
Scheduler.unstable_advanceTime(1);
expect(Scheduler).toFlushExpired([
expect(Scheduler).toFlushAndYieldThrough([
'B (did timeout: true)',
'C (did timeout: true)',
]);

// Expire A
Scheduler.unstable_advanceTime(4600);
expect(Scheduler).toFlushExpired(['A (did timeout: true)']);
expect(Scheduler).toFlushAndYieldThrough(['A (did timeout: true)']);

// Flush the rest without expiring
expect(Scheduler).toFlushAndYield([
Expand All @@ -133,16 +133,6 @@ describe('Scheduler', () => {
]);
});

it('has a default expiration of ~5 seconds', () => {
scheduleCallback(NormalPriority, () => Scheduler.unstable_yieldValue('A'));

Scheduler.unstable_advanceTime(4999);
expect(Scheduler).toHaveYielded([]);

Scheduler.unstable_advanceTime(1);
expect(Scheduler).toFlushExpired(['A']);
});

it('continues working on same task after yielding', () => {
scheduleCallback(NormalPriority, () => {
Scheduler.unstable_advanceTime(100);
Expand Down Expand Up @@ -191,35 +181,6 @@ describe('Scheduler', () => {
expect(Scheduler).toFlushAndYield(['C2', 'C3', 'D', 'E']);
});

it('continuation callbacks inherit the expiration of the previous callback', () => {
const tasks = [
['A', 125],
['B', 124],
['C', 100],
['D', 100],
];
const work = () => {
while (tasks.length > 0) {
const [label, ms] = tasks.shift();
Scheduler.unstable_advanceTime(ms);
Scheduler.unstable_yieldValue(label);
if (shouldYield()) {
return work;
}
}
};

// Schedule a high priority callback
scheduleCallback(UserBlockingPriority, work);

// Flush until just before the expiration time
expect(Scheduler).toFlushAndYieldThrough(['A', 'B']);

// Advance time by just a bit more. This should expire all the remaining work.
Scheduler.unstable_advanceTime(1);
expect(Scheduler).toFlushExpired(['C', 'D']);
});

it('continuations are interrupted by higher priority work', () => {
const tasks = [
['A', 100],
Expand Down Expand Up @@ -322,7 +283,7 @@ describe('Scheduler', () => {
// Immediate callback hasn't fired, yet.
expect(Scheduler).toHaveYielded([]);
// They all flush immediately within the subsequent task.
expect(Scheduler).toFlushExpired(['A', 'B', 'C', 'D']);
expect(Scheduler).toFlushUntilNextPaint(['A', 'B', 'C', 'D']);
});

it('nested immediate callbacks are added to the queue of immediate callbacks', () => {
Expand All @@ -341,7 +302,7 @@ describe('Scheduler', () => {
);
expect(Scheduler).toHaveYielded([]);
// C should flush at the end
expect(Scheduler).toFlushExpired(['A', 'B', 'D', 'C']);
expect(Scheduler).toFlushUntilNextPaint(['A', 'B', 'D', 'C']);
});

it('wrapped callbacks have same signature as original callback', () => {
Expand Down Expand Up @@ -406,12 +367,12 @@ describe('Scheduler', () => {
throw new Error('Oops C');
});

expect(() => expect(Scheduler).toFlushExpired()).toThrow('Oops A');
expect(() => expect(Scheduler).toFlushUntilNextPaint()).toThrow('Oops A');
expect(Scheduler).toHaveYielded(['A']);

// B and C flush in a subsequent event. That way, the second error is not
// swallowed.
expect(() => expect(Scheduler).toFlushExpired()).toThrow('Oops C');
expect(() => expect(Scheduler).toFlushUntilNextPaint()).toThrow('Oops C');
expect(Scheduler).toHaveYielded(['B', 'C']);
});

Expand Down
Loading

0 comments on commit 9377006

Please sign in to comment.