Skip to content

Commit cbe65d7

Browse files
authored
Rewrite ReactFiberScheduler for better integration with Scheduler package (#15151)
* Rewrite ReactFiberScheduler Adds a new implementation of ReactFiberScheduler behind a feature flag. We will maintain both implementations in parallel until the new one is proven stable enough to replace the old one. The main difference between the implementations is that the new one is integrated with the Scheduler package's priority levels. * Conditionally add fields to FiberRoot Some fields only used by the old scheduler, and some by the new. * Add separate build that enables new scheduler * Re-enable skipped test If synchronous updates are scheduled by a passive effect, that work should be flushed synchronously, even if flushPassiveEffects is called inside batchedUpdates. * Passive effects have same priority as render * Revert ability to cancel the current callback React doesn't need this anyway because it never schedules callbacks if it's already rendering. * Revert change to FiberDebugPerf Turns out this isn't neccessary. * Fix ReactFiberScheduler dead code elimination Should initialize to nothing, then assign the exports conditionally, instead of initializing to the old exports and then reassigning to the new ones. * Don't yield before commit during sync error retry * Call Scheduler.flushAll unconditionally in tests Instead of wrapping in enableNewScheduler flag.
1 parent bca6a8f commit cbe65d7

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/__tests__/ReactTestRenderer-test.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,25 @@
99

1010
'use strict';
1111

12-
const ReactDOM = require('react-dom');
13-
14-
// Isolate test renderer.
15-
jest.resetModules();
16-
const React = require('react');
17-
const ReactCache = require('react-cache');
18-
const ReactTestRenderer = require('react-test-renderer');
12+
let ReactDOM;
13+
let React;
14+
let ReactCache;
15+
let ReactTestRenderer;
16+
let Scheduler;
1917

2018
describe('ReactTestRenderer', () => {
19+
beforeEach(() => {
20+
jest.resetModules();
21+
ReactDOM = require('react-dom');
22+
23+
// Isolate test renderer.
24+
jest.resetModules();
25+
React = require('react');
26+
ReactCache = require('react-cache');
27+
ReactTestRenderer = require('react-test-renderer');
28+
Scheduler = require('scheduler');
29+
});
30+
2131
it('should warn if used to render a ReactDOM portal', () => {
2232
const container = document.createElement('div');
2333
expect(() => {
@@ -62,13 +72,15 @@ describe('ReactTestRenderer', () => {
6272
const root = ReactTestRenderer.create(<App text="initial" />);
6373
PendingResources.initial('initial');
6474
await Promise.resolve();
75+
Scheduler.flushAll();
6576
expect(root.toJSON()).toEqual('initial');
6677

6778
root.update(<App text="dynamic" />);
6879
expect(root.toJSON()).toEqual('fallback');
6980

7081
PendingResources.dynamic('dynamic');
7182
await Promise.resolve();
83+
Scheduler.flushAll();
7284
expect(root.toJSON()).toEqual('dynamic');
7385

7486
done();
@@ -88,13 +100,15 @@ describe('ReactTestRenderer', () => {
88100
const root = ReactTestRenderer.create(<App text="initial" />);
89101
PendingResources.initial('initial');
90102
await Promise.resolve();
103+
Scheduler.flushAll();
91104
expect(root.toJSON().children).toEqual(['initial']);
92105

93106
root.update(<App text="dynamic" />);
94107
expect(root.toJSON().children).toEqual(['fallback']);
95108

96109
PendingResources.dynamic('dynamic');
97110
await Promise.resolve();
111+
Scheduler.flushAll();
98112
expect(root.toJSON().children).toEqual(['dynamic']);
99113

100114
done();

0 commit comments

Comments
 (0)