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

Add app-path-routes manifest #38420

Merged
merged 8 commits into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
22 changes: 22 additions & 0 deletions packages/next/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ import {
SERVER_FILES_MANIFEST,
STATIC_STATUS_PAGES,
MIDDLEWARE_MANIFEST,
APP_PATHS_MANIFEST,
APP_PATH_ROUTES_MANIFEST,
} from '../shared/lib/constants'
import { getSortedRoutes, isDynamicRoute } from '../shared/lib/router/utils'
import { __ApiPreviewProps } from '../server/api-utils'
Expand Down Expand Up @@ -110,6 +112,7 @@ import { getNamedRouteRegex } from '../shared/lib/router/utils/route-regex'
import { flatReaddir } from '../lib/flat-readdir'
import { RemotePattern } from '../shared/lib/image-config'
import { eventSwcPlugins } from '../telemetry/events/swc-plugins'
import { normalizeAppPath } from '../shared/lib/router/utils/app-paths'

export type SsgRoute = {
initialRevalidateSeconds: number | false
Expand Down Expand Up @@ -685,6 +688,7 @@ export default async function build(
REACT_LOADABLE_MANIFEST,
config.optimizeFonts ? path.join(serverDir, FONT_MANIFEST) : null,
BUILD_ID_FILE,
appDir ? path.join(serverDir, APP_PATHS_MANIFEST) : null,
]
.filter(nonNullable)
.map((file) => path.join(config.distDir, file)),
Expand Down Expand Up @@ -1614,6 +1618,24 @@ export default async function build(
'utf8'
)

if (appDir) {
const appPathsManifest = JSON.parse(
await promises.readFile(
path.join(distDir, serverDir, APP_PATHS_MANIFEST),
'utf8'
)
)
const appPathRoutes: Record<string, string> = {}

Object.keys(appPathsManifest).forEach((entry) => {
appPathRoutes[entry] = normalizeAppPath(entry) || '/'
})
await promises.writeFile(
path.join(distDir, APP_PATH_ROUTES_MANIFEST),
JSON.stringify(appPathRoutes, null, 2)
)
}

const middlewareManifest: MiddlewareManifest = JSON.parse(
await promises.readFile(
path.join(distDir, serverDir, MIDDLEWARE_MANIFEST),
Expand Down
10 changes: 6 additions & 4 deletions packages/next/server/app-render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ import { stripInternalQueries } from './utils'
import { NextApiRequestCookies } from './api-utils'
import { matchSegment } from '../client/components/match-segments'

const ReactDOMServer = process.env.__NEXT_REACT_ROOT
? require('react-dom/server.browser')
: require('react-dom/server')

export type RenderOptsPartial = {
err?: Error | null
dev?: boolean
Expand Down Expand Up @@ -305,6 +301,12 @@ export async function renderToHTML(
renderOpts: RenderOpts,
isPagesDir: boolean
): Promise<RenderResult | null> {
// this needs to be required lazily so that `next-server` can set
// the env before we require
const ReactDOMServer = process.env.__NEXT_REACT_ROOT
ijjk marked this conversation as resolved.
Show resolved Hide resolved
? require('react-dom/server.browser')
: require('react-dom/server')

// don't modify original query object
query = Object.assign({}, query)

Expand Down
1 change: 1 addition & 0 deletions packages/next/shared/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const PHASE_DEVELOPMENT_SERVER = 'phase-development-server'
export const PHASE_TEST = 'phase-test'
export const PAGES_MANIFEST = 'pages-manifest.json'
export const APP_PATHS_MANIFEST = 'app-paths-manifest.json'
export const APP_PATH_ROUTES_MANIFEST = 'app-path-routes-manifest.json'
export const BUILD_MANIFEST = 'build-manifest.json'
export const EXPORT_MARKER = 'export-marker.json'
export const EXPORT_DETAIL = 'export-detail.json'
Expand Down