Skip to content

Commit 4050a8a

Browse files
authored
Add postpone handling in app-page handler (#86101)
This adds the resume postpone handling into the `app-page` handler so it doesn't rely on `base-server`.
1 parent 35d6fdf commit 4050a8a

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

packages/next/src/build/templates/app-page.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import {
5151
CACHE_ONE_YEAR,
5252
HTML_CONTENT_TYPE_HEADER,
5353
NEXT_CACHE_TAGS_HEADER,
54+
NEXT_RESUME_HEADER,
5455
} from '../../lib/constants'
5556
import type { CacheControl } from '../../server/lib/cache-control'
5657
import { ENCODED_TAGS } from '../../server/stream-utils/encoded-tags'
@@ -121,6 +122,10 @@ export async function handler(
121122
if (routeModule.isDev) {
122123
addRequestMeta(req, 'devRequestTimingInternalsEnd', process.hrtime.bigint())
123124
}
125+
const isMinimalMode = Boolean(
126+
process.env.MINIMAL_MODE || getRequestMeta(req, 'minimalMode')
127+
)
128+
124129
let srcPage = 'VAR_DEFINITION_PAGE'
125130

126131
// turbopack doesn't normalize `/index` in the page name
@@ -135,10 +140,6 @@ export async function handler(
135140
const multiZoneDraftMode = process.env
136141
.__NEXT_MULTI_ZONE_DRAFT_MODE as any as boolean
137142

138-
const isMinimalMode = Boolean(
139-
process.env.MINIMAL_MODE || getRequestMeta(req, 'minimalMode')
140-
)
141-
142143
const prepareResult = await routeModule.prepare(req, res, {
143144
srcPage,
144145
multiZoneDraftMode,
@@ -219,6 +220,25 @@ export async function handler(
219220
nextConfig.experimental.ppr
220221
)
221222

223+
if (
224+
!getRequestMeta(req, 'postponed') &&
225+
couldSupportPPR &&
226+
req.headers[NEXT_RESUME_HEADER] === '1' &&
227+
req.method === 'POST'
228+
) {
229+
// Decode the postponed state from the request body, it will come as
230+
// an array of buffers, so collect them and then concat them to form
231+
// the string.
232+
233+
const body: Array<Buffer> = []
234+
for await (const chunk of req) {
235+
body.push(chunk)
236+
}
237+
const postponed = Buffer.concat(body).toString('utf8')
238+
239+
addRequestMeta(req, 'postponed', postponed)
240+
}
241+
222242
// When enabled, this will allow the use of the `?__nextppronly` query to
223243
// enable debugging of the static shell.
224244
const hasDebugStaticShellQuery =

0 commit comments

Comments
 (0)