Fix stale executionContext after breakpoint/alert interruption (#17355)#35865
Open
gpardhivvarma wants to merge 1 commit intofacebook:mainfrom
Open
Fix stale executionContext after breakpoint/alert interruption (#17355)#35865gpardhivvarma wants to merge 1 commit intofacebook:mainfrom
gpardhivvarma wants to merge 1 commit intofacebook:mainfrom
Conversation
…ook#17355) When execution is interrupted by a breakpoint, alert(), or browser debugging pause (particularly in Firefox), the finally blocks that normally reset executionContext may not run. This leaves RenderContext or CommitContext flags set even though workInProgress and workInProgressRoot are both null. On resume, performWorkOnRoot and completeRoot see the stale flags and throw "Should not already be working." Add fixStaleExecutionContext() which detects this mismatch and clears the stale render/commit flags before the assertion. Called at the top of performWorkOnRoot and after flushPendingEffects in completeRoot.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #17355.
When execution is interrupted by a breakpoint,
alert(), or a browser debugging pause (particularly in Firefox), thefinallyblocks that normally resetexecutionContextmay not run. This leavesRenderContextorCommitContextflags set even thoughworkInProgressandworkInProgressRootare both null.On resume,
performWorkOnRootandcompleteRootsee the stale flags and throw "Should not already be working."This adds
fixStaleExecutionContext()which detects this mismatch — render/commit flags are set but nothing is actually in progress — and clears just those flags before the assertion. It's called at the top ofperformWorkOnRootand afterflushPendingEffectsincompleteRoot, the two places that guard with this check.The fix is defensive: it only activates when the context is genuinely stale, so normal execution paths are unaffected.
How did you test this change?
yarn prettier— no formatting issuesyarn linc— lint passes on changed filesyarn flow dom-browser— no type errorsyarn test packages/react-reconciler/src/__tests__/— all 76 suites pass (1132 tests)This edge case is inherently difficult to unit-test because it requires simulating an external interruption (breakpoint/alert) mid-render. The fix only runs when executionContext is clearly inconsistent with the actual work-in-progress state, and the existing test suite confirms it doesn't change behavior under normal conditions.