Skip to content

Commit

Permalink
Pages Route Module Rendering (vercel#50404)
Browse files Browse the repository at this point in the history
This starts the process of moving the rendering logic for pages into the
bundle. The `render` method on the module now provides the same
capability as the underlying `renderHTML` method available on the
`NextNodeServer`. In the next few change sets, more layers of the
rendering pipeline will shift into the bundled code, removing them from
the main boot path.

---------

Co-authored-by: JJ Kasper <[email protected]>
  • Loading branch information
2 people authored and hydRAnger committed Jun 12, 2023
1 parent 4d23db9 commit 94c1222
Show file tree
Hide file tree
Showing 12 changed files with 240 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,18 +241,25 @@ export default function startHandler({
renderOpts
)

// Set when `getStaticProps` returns `notFound: true`.
const isNotFound = renderResult.metadata().isNotFound
const {
metadata: {
// Set when `getStaticProps` returns `notFound: true`.
isNotFound,
// Set when `getStaticProps` returns `redirect: { destination, permanent, statusCode }`.
isRedirect,
},
} = renderResult

if (isNotFound) {
return createNotFoundResponse(isDataReq)
}

// Set when `getStaticProps` returns `redirect: { destination, permanent, statusCode }`.
const isRedirect = renderResult.metadata().isRedirect

if (isRedirect && !isDataReq) {
const pageProps = renderResult.metadata().pageData.pageProps
const {
metadata: {
pageData: { pageProps },
},
} = renderResult
const redirect = {
destination: pageProps.__N_REDIRECT,
statusCode: pageProps.__N_REDIRECT_STATUS,
Expand Down Expand Up @@ -286,7 +293,9 @@ export default function startHandler({

if (isDataReq) {
// TODO(from next.js): change this to a different passing mechanism
const pageData = renderResult.metadata().pageData
const {
metadata: { pageData },
} = renderResult
return {
type: 'response',
statusCode: res.statusCode,
Expand Down
21 changes: 10 additions & 11 deletions packages/next/src/export/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,9 @@ export default async function exportPage({
curRenderOpts as any
)
const html = result.toUnchunkedString()
const renderResultMeta = result.metadata()
const flightData = renderResultMeta.pageData
const revalidate = renderResultMeta.revalidate
const { metadata } = result
const flightData = metadata.pageData
const revalidate = metadata.revalidate
results.fromBuildExportRevalidate = revalidate

if (revalidate !== 0) {
Expand Down Expand Up @@ -538,7 +538,7 @@ export default async function exportPage({
)
}

const staticBailoutInfo = renderResultMeta.staticBailoutInfo || {}
const staticBailoutInfo = metadata.staticBailoutInfo || {}

if (
revalidate === 0 &&
Expand Down Expand Up @@ -627,7 +627,7 @@ export default async function exportPage({
}
}

results.ssgNotFound = renderResult?.metadata().isNotFound
results.ssgNotFound = renderResult?.metadata.isNotFound

const validateAmp = async (
rawAmpHtml: string,
Expand Down Expand Up @@ -701,9 +701,8 @@ export default async function exportPage({
}
}

const renderResultMeta =
renderResult?.metadata() || ampRenderResult?.metadata() || {}
if (renderResultMeta.pageData) {
const metadata = renderResult?.metadata || ampRenderResult?.metadata || {}
if (metadata.pageData) {
const dataFile = join(
pagesDataDir,
htmlFilename.replace(/\.html$/, '.json')
Expand All @@ -712,19 +711,19 @@ export default async function exportPage({
await promises.mkdir(dirname(dataFile), { recursive: true })
await promises.writeFile(
dataFile,
JSON.stringify(renderResultMeta.pageData),
JSON.stringify(metadata.pageData),
'utf8'
)

if (hybridAmp) {
await promises.writeFile(
dataFile.replace(/\.json$/, '.amp.json'),
JSON.stringify(renderResultMeta.pageData),
JSON.stringify(metadata.pageData),
'utf8'
)
}
}
results.fromBuildExportRevalidate = renderResultMeta.revalidate
results.fromBuildExportRevalidate = metadata.revalidate

if (!results.ssgNotFound) {
// don't attempt writing to disk if getStaticProps returned not found
Expand Down
Loading

0 comments on commit 94c1222

Please sign in to comment.