Skip to content

Commit

Permalink
Prevent setState callback firing during rebase
Browse files Browse the repository at this point in the history
Before enqueueing the effect, adds a guard to check if the update was
already committed.
  • Loading branch information
acdlite committed May 12, 2021
1 parent 3fac6a7 commit a807e67
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion packages/react-reconciler/src/ReactUpdateQueue.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,12 @@ export function processUpdateQueue<State>(
instance,
);
const callback = update.callback;
if (callback !== null) {
if (
callback !== null &&
// If the update was already committed, we should not queue its
// callback again.
update.lane !== NoLane
) {
workInProgress.flags |= Callback;
const effects = queue.effects;
if (effects === null) {
Expand Down
7 changes: 6 additions & 1 deletion packages/react-reconciler/src/ReactUpdateQueue.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,12 @@ export function processUpdateQueue<State>(
instance,
);
const callback = update.callback;
if (callback !== null) {
if (
callback !== null &&
// If the update was already committed, we should not queue its
// callback again.
update.lane !== NoLane
) {
workInProgress.flags |= Callback;
const effects = queue.effects;
if (effects === null) {
Expand Down

0 comments on commit a807e67

Please sign in to comment.