Skip to content

Commit

Permalink
refactor(after): remove unnecessary conditionals (#73447)
Browse files Browse the repository at this point in the history
These should've been removed in #73190 because we're always creating a
`closeController`.
  • Loading branch information
lubieowoce authored Dec 2, 2024
1 parent 18e8bfb commit 616bcb3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 26 deletions.
12 changes: 5 additions & 7 deletions packages/next/src/server/web/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,11 @@ export async function adapter(
} finally {
// middleware cannot stream, so we can consider the response closed
// as soon as the handler returns.
if (closeController) {
// we can delay running it until a bit later --
// if it's needed, we'll have a `waitUntil` lock anyway.
setTimeout(() => {
closeController!.dispatchClose()
}, 0)
}
// we can delay running it until a bit later --
// if it's needed, we'll have a `waitUntil` lock anyway.
setTimeout(() => {
closeController.dispatchClose()
}, 0)
}
}
)
Expand Down
34 changes: 15 additions & 19 deletions packages/next/src/server/web/edge-route-module-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,25 +127,21 @@ export class EdgeRouteModuleWrapper {
}
evt.waitUntil(Promise.all(waitUntilPromises))

if (closeController) {
const _closeController = closeController // TS annoyance - "possibly undefined" in callbacks

if (!res.body) {
// we can delay running it until a bit later --
// if it's needed, we'll have a `waitUntil` lock anyway.
setTimeout(() => _closeController.dispatchClose(), 0)
} else {
// NOTE: if this is a streaming response, onClose may be called later,
// so we can't rely on `closeController.listeners` -- it might be 0 at this point.
const trackedBody = trackStreamConsumed(res.body, () =>
_closeController.dispatchClose()
)
res = new Response(trackedBody, {
status: res.status,
statusText: res.statusText,
headers: res.headers,
})
}
if (!res.body) {
// we can delay running it until a bit later --
// if it's needed, we'll have a `waitUntil` lock anyway.
setTimeout(() => closeController.dispatchClose(), 0)
} else {
// NOTE: if this is a streaming response, onClose may be called later,
// so we can't rely on `closeController.listeners` -- it might be 0 at this point.
const trackedBody = trackStreamConsumed(res.body, () =>
closeController.dispatchClose()
)
res = new Response(trackedBody, {
status: res.status,
statusText: res.statusText,
headers: res.headers,
})
}

return res
Expand Down

0 comments on commit 616bcb3

Please sign in to comment.