Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pages Route Module Rendering #50404

Merged
merged 19 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
aa63335
feat: disable handling for non-app-route definitions
wyattjoh May 24, 2023
ed9bcbe
feat: handle pages routes with route module
wyattjoh May 25, 2023
26139e7
Merge branch 'canary' into wyattjoh/pages-route-rendering
wyattjoh May 26, 2023
488281a
fix: add next font manifest to renderOpts
wyattjoh May 27, 2023
b1d3907
Merge branch 'canary' into wyattjoh/pages-route-rendering
wyattjoh May 29, 2023
f32fe81
refactor: cleanup route match detection
wyattjoh May 29, 2023
f3d0754
fix: only add cache tags when they're available
wyattjoh May 30, 2023
a89d43f
Merge branch 'canary' into wyattjoh/pages-route-rendering
wyattjoh May 30, 2023
6ae3694
Merge branch 'canary' into wyattjoh/pages-route-rendering
wyattjoh May 30, 2023
230ee75
Merge branch 'canary' into wyattjoh/pages-route-rendering
wyattjoh May 31, 2023
1ed0493
fix: remove cache tags from minimal response
wyattjoh May 31, 2023
b4cba61
refactor: modified mutability on render result
wyattjoh May 31, 2023
46d1287
Merge branch 'canary' into wyattjoh/pages-route-rendering
wyattjoh May 31, 2023
61b51cb
fix: adjust kill app mechanism for tests
wyattjoh Jun 1, 2023
989f4ce
Merge branch 'canary' into wyattjoh/pages-route-rendering
wyattjoh Jun 1, 2023
606abbb
Merge branch 'canary' into wyattjoh/pages-route-rendering
wyattjoh Jun 2, 2023
aa8f15b
Merge branch 'canary' into wyattjoh/pages-route-rendering
wyattjoh Jun 5, 2023
b8f1d6e
Merge branch 'canary' into wyattjoh/pages-route-rendering
ijjk Jun 6, 2023
06a80c8
Merge branch 'canary' into wyattjoh/pages-route-rendering
wyattjoh Jun 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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