Skip to content

Commit bfa66bf

Browse files
committed
Fix setState being ignored in Safari
1 parent 51947a1 commit bfa66bf

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

packages/react-reconciler/src/ReactFiberWorkLoop.new.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,15 @@ function ensureRootIsScheduled(root: FiberRoot, currentTime: number) {
708708
// of `act`.
709709
ReactCurrentActQueue.current.push(flushSyncCallbacks);
710710
} else {
711-
scheduleMicrotask(flushSyncCallbacks);
711+
scheduleMicrotask(() => {
712+
// In Safari, appending an iframe forces microtasks to run.
713+
// https://github.com/facebook/react/issues/22459
714+
// We don't support running callbacks in the middle of render
715+
// or commit so we need to check against that.
716+
if (executionContext === NoContext) {
717+
flushSyncCallbacks();
718+
}
719+
});
712720
}
713721
} else {
714722
// Flush the queue in an Immediate task.

packages/react-reconciler/src/ReactFiberWorkLoop.old.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,15 @@ function ensureRootIsScheduled(root: FiberRoot, currentTime: number) {
708708
// of `act`.
709709
ReactCurrentActQueue.current.push(flushSyncCallbacks);
710710
} else {
711-
scheduleMicrotask(flushSyncCallbacks);
711+
scheduleMicrotask(() => {
712+
// In Safari, appending an iframe forces microtasks to run.
713+
// https://github.com/facebook/react/issues/22459
714+
// We don't support running callbacks in the middle of render
715+
// or commit so we need to check against that.
716+
if (executionContext === NoContext) {
717+
flushSyncCallbacks();
718+
}
719+
});
712720
}
713721
} else {
714722
// Flush the queue in an Immediate task.

0 commit comments

Comments
 (0)