diff --git a/packages/react-server/src/ReactFlightReplyServer.js b/packages/react-server/src/ReactFlightReplyServer.js index 4d5a6da8b8e..88781cc6eb8 100644 --- a/packages/react-server/src/ReactFlightReplyServer.js +++ b/packages/react-server/src/ReactFlightReplyServer.js @@ -133,14 +133,20 @@ ReactPromise.prototype.then = function ( // 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; + const visited = new Set(); while (inspectedValue instanceof ReactPromise) { cycleProtection++; - if (inspectedValue === chunk || cycleProtection > 1000) { + if ( + inspectedValue === chunk || + visited.has(inspectedValue) || + cycleProtection > 1000 + ) { if (typeof reject === 'function') { reject(new Error('Cannot have cyclic thenables.')); } return; } + visited.add(inspectedValue); if (inspectedValue.status === INITIALIZED) { inspectedValue = inspectedValue.value; } else {