From b45bb335db5b3632329d6b41e5a790ff6f1a7ff7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Markb=C3=A5ge?= Date: Thu, 11 Dec 2025 17:23:01 -0500 Subject: [PATCH] [Flight] Add extra loop protection (#35351) In case we get into loops. --- packages/react-server/src/ReactFlightReplyServer.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/react-server/src/ReactFlightReplyServer.js b/packages/react-server/src/ReactFlightReplyServer.js index 1831a35857..4d5a6da8b8 100644 --- a/packages/react-server/src/ReactFlightReplyServer.js +++ b/packages/react-server/src/ReactFlightReplyServer.js @@ -132,8 +132,10 @@ ReactPromise.prototype.then = function ( 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.')); }