Fix 'Should not already be working' error in Firefox after breakpoint… #33420
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix: "Should not already be working" Error in React 16.11 During Debugging
Summary
This PR addresses issue #17355 where users encounter the error message "Should not already be working" after using breakpoints or alerts in Firefox and older versions of Chrome (specifically 68.0.3440 on Windows 7) when using React 16.11.
The issue occurs because when a breakpoint or alert interrupts the JavaScript execution flow, React's internal execution context flags don't get properly reset, leading to this error when execution resumes.
The error is thrown in the React Fiber reconciler when it detects it's already "working" (rendering or committing) and tries to perform work again, which is normally an inconsistent state. However, in debugging scenarios with breakpoints or alerts, this state can occur without being a real bug.
Changes Made
Modified error handling in
ReactFiberWorkLoop.js
in two locations where the "Should not already be working" error is thrown:performWorkOnRoot
functionflushPendingEffects
callAdded more resilient error handling:
In development mode (
__DEV__
):In production mode:
How Did You Test This Change?
I tested this change by:
Conclusion
This change makes React more resilient to debugging interruptions while maintaining the integrity of its error checking system. It significantly improves the developer experience when using breakpoints or alerts in older browsers.
Feedback welcome.