Skip to content

Commit b45bb33

Browse files
authored
[Flight] Add extra loop protection (#35351)
In case we get into loops.
1 parent 80cb7a9 commit b45bb33

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

packages/react-server/src/ReactFlightReplyServer.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,10 @@ ReactPromise.prototype.then = function <T>(
132132
let inspectedValue = chunk.value;
133133
// Recursively check if the value is itself a ReactPromise and if so if it points
134134
// back to itself. This helps catch recursive thenables early error.
135+
let cycleProtection = 0;
135136
while (inspectedValue instanceof ReactPromise) {
136-
if (inspectedValue === chunk) {
137+
cycleProtection++;
138+
if (inspectedValue === chunk || cycleProtection > 1000) {
137139
if (typeof reject === 'function') {
138140
reject(new Error('Cannot have cyclic thenables.'));
139141
}

0 commit comments

Comments
 (0)