Skip to content

Commit

Permalink
fix: ensure background work is finished when response has 3xx or 5xx …
Browse files Browse the repository at this point in the history
…status code
  • Loading branch information
pieh committed Jan 16, 2025
1 parent 62ed00c commit 3fd8d77
Showing 1 changed file with 0 additions and 11 deletions.
11 changes: 0 additions & 11 deletions src/run/handlers/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,6 @@ export default async (request: Request) => {
setVaryHeaders(response.headers, request, nextConfig)
setCacheStatusHeader(response.headers)

// Temporary workaround for an issue where sending a response with an empty
// body causes an unhandled error. This doesn't catch everything, but redirects are the
// most common case of sending empty bodies. We can't check it directly because these are streams.
// The side effect is that responses which do contain data will not be streamed to the client,
// but that's fine for redirects.
// TODO: Remove once a fix has been rolled out.
if ((response.status > 300 && response.status < 400) || response.status >= 500) {
const body = await response.text()
return new Response(body || null, response)
}

const keepOpenUntilNextFullyRendered = new TransformStream({
async flush() {
// it's important to keep the stream open until the next handler has finished
Expand Down

0 comments on commit 3fd8d77

Please sign in to comment.