diff --git a/packages/react-client/src/ReactFlightClient.js b/packages/react-client/src/ReactFlightClient.js index 61a67bce9d803..b966645623bbb 100644 --- a/packages/react-client/src/ReactFlightClient.js +++ b/packages/react-client/src/ReactFlightClient.js @@ -1010,10 +1010,15 @@ export function reportGlobalError( if (__DEV__) { const debugChannel = response._debugChannel; if (debugChannel !== undefined) { - // If we don't have any more ways of reading data, we don't have to send any - // more neither. So we close the writable side. + // If we don't have any more ways of reading data, we don't have to send + // any more neither. So we close the writable side. closeDebugChannel(debugChannel); response._debugChannel = undefined; + // Make sure the debug channel is not closed a second time when the + // Response gets GC:ed. + if (debugChannelRegistry !== null) { + debugChannelRegistry.unregister(response); + } } } } @@ -2434,7 +2439,7 @@ function ResponseInstance( // When a Response gets GC:ed because nobody is referring to any of the // objects that lazily load from the Response anymore, then we can close // the debug channel. - debugChannelRegistry.register(this, debugChannel); + debugChannelRegistry.register(this, debugChannel, this); } } }