[Flight] Add extra loop protection (#35351)

In case we get into loops.
This commit is contained in:
Sebastian Markbåge
2025-12-11 17:23:01 -05:00
committed by GitHub
parent 80cb7a9925
commit b45bb335db

View File

@@ -132,8 +132,10 @@ ReactPromise.prototype.then = function <T>(
let inspectedValue = chunk.value;
// Recursively check if the value is itself a ReactPromise and if so if it points
// back to itself. This helps catch recursive thenables early error.
let cycleProtection = 0;
while (inspectedValue instanceof ReactPromise) {
if (inspectedValue === chunk) {
cycleProtection++;
if (inspectedValue === chunk || cycleProtection > 1000) {
if (typeof reject === 'function') {
reject(new Error('Cannot have cyclic thenables.'));
}