Skip to content

Commit 46bd11a

Browse files
lunaruanacdlite
authored andcommitted
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
1 parent 933c664 commit 46bd11a

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

packages/react-reconciler/src/SchedulerWithReactIntegration.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,15 @@ function flushSyncCallbackQueueImpl() {
172172
let i = 0;
173173
try {
174174
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+
});
181184
syncQueue = null;
182185
} catch (error) {
183186
// If something throws, leave the remaining callbacks on the queue.

packages/react-reconciler/src/__tests__/ReactSchedulerIntegration-test.internal.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ describe('ReactSchedulerIntegration', () => {
5555
}
5656
}
5757

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+
5869
it('has correct priority during rendering', () => {
5970
function ReadPriority() {
6071
Scheduler.unstable_yieldValue(

0 commit comments

Comments
 (0)