Unverified Commit 81eccb7e authored by Shu Ding's avatar Shu Ding Committed by GitHub

Release unnecessary memory on hydration finish (#84967)

Clear global data array to release memory after server data is flushed.

For large apps we found that up to megabytes of data only used by
hydration can be held by `window.__next_f` for the entire session.
parent c6767204
...@@ -155,7 +155,13 @@ if (document.readyState === 'loading') { ...@@ -155,7 +155,13 @@ if (document.readyState === 'loading') {
} }
const nextServerDataLoadingGlobal = (self.__next_f = self.__next_f || []) 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.forEach(nextServerDataCallback)
nextServerDataLoadingGlobal.length = 0
// Patch its push method so subsequent chunks are handled (but not actually pushed to the array).
nextServerDataLoadingGlobal.push = nextServerDataCallback nextServerDataLoadingGlobal.push = nextServerDataCallback
const readable = new ReadableStream({ const readable = new ReadableStream({
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment