@samitouri / QOS-React-2 / commits / 46bd11ac3e

Flush sync bug (#16027)

* added flush sync test * added code to run flushSync with ImmediatePriority * added code to run flushSync with ImmediatePriority * fixed flow error * fixed flow error

lunaruan committed Jul 1, 2019 at 16:58 UTC 46bd11ac3e086fc25b2704679c69c089803779f7
2 files changed +20 -6
packages/react-reconciler/src/SchedulerWithReactIntegration.js
+9 -6
@@ -172,12 +172,15 @@ function flushSyncCallbackQueueImpl() {
172 let i = 0;
173 try {
174 const isSync = true;
175 - for (; i < syncQueue.length; i++) {
176 - let callback = syncQueue[i];
177 - do {
178 - callback = callback(isSync);
179 - } while (callback !== null);
180 - }
175 + const queue = syncQueue;
176 + runWithPriority(ImmediatePriority, () => {
177 + for (; i < queue.length; i++) {
178 + let callback = queue[i];
179 + do {
180 + callback = callback(isSync);
181 + } while (callback !== null);
182 + }
183 + });
184 syncQueue = null;
185 } catch (error) {
186 // If something throws, leave the remaining callbacks on the queue.
packages/react-reconciler/src/__tests__/ReactSchedulerIntegration-test.internal.js
+11
@@ -55,6 +55,17 @@ describe('ReactSchedulerIntegration', () => {
55 }
56 }
57
58 + it('flush sync has correct priority', () => {
59 + function ReadPriority() {
60 + Scheduler.unstable_yieldValue(
61 + 'Priority: ' + getCurrentPriorityAsString(),
62 + );
63 + return null;
64 + }
65 + ReactNoop.flushSync(() => ReactNoop.render(<ReadPriority />));
66 + expect(Scheduler).toHaveYielded(['Priority: Immediate']);
67 + });
68 +
69 it('has correct priority during rendering', () => {
70 function ReadPriority() {
71 Scheduler.unstable_yieldValue(