Unverified Commit d4d79b2d authored by Shu Ding's avatar Shu Ding Committed by GitHub

Fix chunk buffering for server components (#34474)

parent 74fa4d4b
......@@ -1764,19 +1764,28 @@ function createInlineDataStream(
if (!dataStreamFinished && dataStream) {
const dataStreamReader = dataStream.getReader()
dataStreamFinished = (async () => {
try {
while (true) {
const { done, value } = await dataStreamReader.read()
if (done) {
return
// We are buffering here for the inlined data stream because the
// "shell" stream might be chunkenized again by the underlying stream
// implementation, e.g. with a specific high-water mark. To ensure it's
// the safe timing to pipe the data stream, this extra tick is
// necessary.
dataStreamFinished = new Promise((res) =>
setTimeout(async () => {
try {
while (true) {
const { done, value } = await dataStreamReader.read()
if (done) {
return res()
}
controller.enqueue(value)
}
controller.enqueue(value)
} catch (err) {
controller.error(err)
}
} catch (err) {
controller.error(err)
}
})()
res()
}, 0)
)
}
},
flush() {
......
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