Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flushing suspense fallbacks at the end of Act when the scheduler is mocked #19471

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/react-reconciler/src/ReactFiberWorkLoop.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -3717,7 +3717,7 @@ function finishPendingInteractions(root, committedLanes) {
// access to the same internals that we do here. Some trade offs in the
// implementation no longer make sense.

let isFlushingAct = false;
let isFlushingAct = null;
let isInsideThisAct = false;

// TODO: Yes, this is confusing. See above comment. We'll refactor it.
Expand All @@ -3726,6 +3726,13 @@ function shouldForceFlushFallbacksInDEV() {
// Never force flush in production. This function should get stripped out.
return false;
}

// `isFlushingAct` is used by ReactTestRenderer version of `act`.
if (isFlushingAct != null) {
// Flush callbacks at the end.
return isFlushingAct;
}

// `IsThisRendererActing.current` is used by ReactTestUtils version of `act`.
if (IsThisRendererActing.current) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The core issue for the bug I'm fixing is that IsThisRendererActing.current is not reset to false before we check shouldForceFlushFallbacksInDEV, meaning that we miss the isFlushingAct = true value, and we schedule the fallback here instead of committing it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@acdlite what was the expected behavior here? Should we be checking for isFlushingAct first?

Is the test that failed correct or is it actually wrong?

// `isInsideAct` is only used by the reconciler implementation of `act`.
Expand Down
9 changes: 8 additions & 1 deletion packages/react-reconciler/src/ReactFiberWorkLoop.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -3573,7 +3573,7 @@ function finishPendingInteractions(root, committedLanes) {
// access to the same internals that we do here. Some trade offs in the
// implementation no longer make sense.

let isFlushingAct = false;
let isFlushingAct = null;
let isInsideThisAct = false;

// TODO: Yes, this is confusing. See above comment. We'll refactor it.
Expand All @@ -3582,6 +3582,13 @@ function shouldForceFlushFallbacksInDEV() {
// Never force flush in production. This function should get stripped out.
return false;
}

// `isFlushingAct` is used by ReactTestRenderer version of `act`.
if (isFlushingAct != null) {
// Flush callbacks at the end.
return isFlushingAct;
}

// `IsThisRendererActing.current` is used by ReactTestUtils version of `act`.
if (IsThisRendererActing.current) {
// `isInsideAct` is only used by the reconciler implementation of `act`.
Expand Down