[Flight] Add extra loop protection (#35351)
In case we get into loops.
Sebastian Markbåge committed
Dec 11, 2025 at 17:23 UTC
b45bb335db5b3632329d6b41e5a790ff6f1a7ff7
1 file changed
+3
-1
packages/react-server/src/ReactFlightReplyServer.js
+3
-1
@@ -132,8 +132,10 @@ ReactPromise.prototype.then = function <T>(
132
let inspectedValue = chunk.value;
133
// Recursively check if the value is itself a ReactPromise and if so if it points
134
// back to itself. This helps catch recursive thenables early error.
135
+ let cycleProtection = 0;
136
while (inspectedValue instanceof ReactPromise) {
136
- if (inspectedValue === chunk) {
137
+ cycleProtection++;
138
+ if (inspectedValue === chunk || cycleProtection > 1000) {
139
if (typeof reject === 'function') {
140
reject(new Error('Cannot have cyclic thenables.'));
141
}