Skip to content

Commit

Permalink
actually make lazy
Browse files Browse the repository at this point in the history
  • Loading branch information
feedthejim committed Oct 12, 2022
1 parent 5487354 commit 65da9a9
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/next/server/app-render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,17 @@ const INTERNAL_COOKIES_INSTANCE = Symbol('internal for cookies readonly')
function readonlyCookiesError() {
return new Error('ReadonlyCookies cannot be modified')
}

function lazy<T>(fn: () => T) {
let value: any
return () => {
if (!value) {
value = fn()
}
return value
}
}

class ReadonlyNextCookies {
[INTERNAL_COOKIES_INSTANCE]: NextCookies

Expand Down Expand Up @@ -1572,7 +1583,7 @@ export async function renderToHTMLOrFlight(
)

const requestStore = {
headers: () => new ReadonlyHeaders(headersWithoutFlight(req.headers)),
headers: lazy(() => new ReadonlyHeaders(headersWithoutFlight(req.headers))),
cookies: new ReadonlyNextCookies({
headers: {
get: (key) => {
Expand Down

0 comments on commit 65da9a9

Please sign in to comment.