Skip to content

Commit a807e67

Browse files
committed
Prevent setState callback firing during rebase
Before enqueueing the effect, adds a guard to check if the update was already committed.
1 parent 3fac6a7 commit a807e67

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,12 @@ export function processUpdateQueue<State>(
580580
instance,
581581
);
582582
const callback = update.callback;
583-
if (callback !== null) {
583+
if (
584+
callback !== null &&
585+
// If the update was already committed, we should not queue its
586+
// callback again.
587+
update.lane !== NoLane
588+
) {
584589
workInProgress.flags |= Callback;
585590
const effects = queue.effects;
586591
if (effects === null) {

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,12 @@ export function processUpdateQueue<State>(
580580
instance,
581581
);
582582
const callback = update.callback;
583-
if (callback !== null) {
583+
if (
584+
callback !== null &&
585+
// If the update was already committed, we should not queue its
586+
// callback again.
587+
update.lane !== NoLane
588+
) {
584589
workInProgress.flags |= Callback;
585590
const effects = queue.effects;
586591
if (effects === null) {

0 commit comments

Comments
 (0)