Fix cyclic thenable detection for multi-node cycles (#35368) #35375
+35
−45
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
This change improves cyclic thenable detection in
ReactFlightReplyServerby tracking visitedReactPromiseinstances during traversal.Previously, the logic only detected direct self-references and relied on a fixed iteration limit to bail out. This meant multi-node cycles (e.g. A → B → C → A or A → B → C → B) were not detected immediately.
The updated implementation introduces a
Setto record visited promises and rejects as soon as a previously seenReactPromiseis encountered, ensuring correct and early detection of all cyclic cases. A safety iteration counter is kept as a secondary defense, although it should not be reached under normal conditions.Fixes #35368
How did you test this change?
ReactPromiseinstances forming different cycle patterns:ReactPromise, instead of iterating until the iteration limit.ReactPromiseor non-INITIALIZEDvalue is reached.Not run via full test suite (change is localized and verified through targeted reproduction).