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