Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix suffix ordering while streaming #34011

Merged
merged 3 commits into from Feb 5, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 11 additions & 16 deletions packages/next/server/render.tsx
Expand Up @@ -1564,14 +1564,14 @@ function createTransformStream({
if (maybePromise) {
await maybePromise
}
writer.close()
await writer.close()
return
}

transform(value, controller)
}
} catch (err) {
writer.abort(err)
await writer.abort(err)
}
})()

Expand Down Expand Up @@ -1634,18 +1634,7 @@ function renderToStream(
suffixUnclosed: encoder.encode(suffix.split(closeTagString)[0]),
}
: null

const { readable, writable } = createTransformStream({
transform(chunk, controller) {
controller.enqueue(chunk)
},

flush(controller) {
if (suffixState) {
controller.enqueue(suffixState.closeTag)
}
},
})
const { readable, writable } = new TransformStream()

const doResolve = () => {
if (!resolved) {
Expand Down Expand Up @@ -1683,10 +1672,16 @@ function renderToStream(
})()
}
},
flush() {
flush(controller) {
const flushClosingTag = () => {
if (suffixState) {
controller.enqueue(suffixState.closeTag)
}
}
if (dataStreamFinished) {
return dataStreamFinished
return dataStreamFinished.then(flushClosingTag)
}
flushClosingTag()
},
})
)
Expand Down
Expand Up @@ -104,4 +104,11 @@ export default function (context) {
'count: 1'
)
})

it('should flush the suffix at the very end', async () => {
await fetchViaHTTP(context.appPort, '/').then(async (response) => {
const result = await resolveStreamResponse(response)
expect(result).toMatch(/<\/body><\/html>/)
})
})
}