diff --git a/packages/next/src/client/app-index.tsx b/packages/next/src/client/app-index.tsx index 88063a5c625296..aeef8bda325870 100644 --- a/packages/next/src/client/app-index.tsx +++ b/packages/next/src/client/app-index.tsx @@ -155,7 +155,13 @@ if (document.readyState === 'loading') { } const nextServerDataLoadingGlobal = (self.__next_f = self.__next_f || []) + +// Consume all buffered chunks and clear the global data array right after to release memory. +// Otherwise it will be retained indefinitely. nextServerDataLoadingGlobal.forEach(nextServerDataCallback) +nextServerDataLoadingGlobal.length = 0 + +// Patch its push method so subsequent chunks are handled (but not actually pushed to the array). nextServerDataLoadingGlobal.push = nextServerDataCallback const readable = new ReadableStream({