Skip to content

Commit

Permalink
avoid re-instantiating Response when not required
Browse files Browse the repository at this point in the history
  • Loading branch information
sassanh committed Nov 2, 2024
1 parent 96c331d commit 960dc6a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 10 additions & 8 deletions packages/next-on-pages/templates/_worker.js/handleRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,17 @@ async function generateResponse(
});
}

const newHeaders = headers.normal;
applyHeaders(newHeaders, resp.headers);
applyHeaders(newHeaders, headers.important);
if (status || resp.status !== 101) {
const newHeaders = headers.normal;
applyHeaders(newHeaders, resp.headers);
applyHeaders(newHeaders, headers.important);

resp = new Response(resp.body, {
...resp,
status: status || resp.status,
headers: newHeaders,
});
resp = new Response(resp.body, {
...resp,
status: status || resp.status,
headers: newHeaders,
});
}

return resp;
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export async function runOrFetchBuildOutputItem(
return new Response('Internal Server Error', { status: 500 });
}

return createMutableResponse(resp);
return resp;
}

/**
Expand Down

0 comments on commit 960dc6a

Please sign in to comment.