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

Drop edge prerender manifest #67787

Merged
merged 3 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 0 additions & 29 deletions packages/next/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,32 +342,6 @@ async function writePrerenderManifest(
manifest: DeepReadonly<PrerenderManifest>
): Promise<void> {
await writeManifest(path.join(distDir, PRERENDER_MANIFEST), manifest)
await writeEdgePartialPrerenderManifest(distDir, manifest)
}

async function writeEdgePartialPrerenderManifest(
distDir: string,
manifest: DeepReadonly<Partial<PrerenderManifest>>
): Promise<void> {
// We need to write a partial prerender manifest to make preview mode settings available in edge middleware.
// Use env vars in JS bundle and inject the actual vars to edge manifest.
const edgePartialPrerenderManifest: DeepReadonly<Partial<PrerenderManifest>> =
{
routes: {},
dynamicRoutes: {},
notFoundRoutes: [],
version: manifest.version,
// Preview props are inlined in the code with dynamic env vars,
// During edge runtime build:
// - local: env vars will be injected through edge-runtime as runtime env vars
// - deployment: env vars will be replaced by edge build pipeline as inline values
}
await writeFileUtf8(
path.join(distDir, PRERENDER_MANIFEST.replace(/\.json$/, '.js')),
`self.__PRERENDER_MANIFEST=${JSON.stringify(
JSON.stringify(edgePartialPrerenderManifest)
)}`
)
}

async function writeClientSsgManifest(
Expand Down Expand Up @@ -1215,8 +1189,6 @@ export default async function build(
'{"type": "commonjs"}'
)

await writeEdgePartialPrerenderManifest(distDir, {})

const outputFileTracingRoot =
config.experimental.outputFileTracingRoot || dir

Expand Down Expand Up @@ -1259,7 +1231,6 @@ export default async function build(
path.relative(distDir, pagesManifestPath),
BUILD_MANIFEST,
PRERENDER_MANIFEST,
PRERENDER_MANIFEST.replace(/\.json$/, '.js'),
path.join(SERVER_DIRECTORY, MIDDLEWARE_MANIFEST),
path.join(SERVER_DIRECTORY, MIDDLEWARE_BUILD_MANIFEST + '.js'),
path.join(
Expand Down
2 changes: 0 additions & 2 deletions packages/next/src/build/templates/edge-ssr-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ declare const nextConfig: NextConfigComplete
const maybeJSONParse = (str?: string) => (str ? JSON.parse(str) : undefined)

const buildManifest: BuildManifest = self.__BUILD_MANIFEST as any
const prerenderManifest = maybeJSONParse(self.__PRERENDER_MANIFEST)
const reactLoadableManifest = maybeJSONParse(self.__REACT_LOADABLE_MANIFEST)
const rscManifest = self.__RSC_MANIFEST?.['VAR_PAGE']
const rscServerManifest = maybeJSONParse(self.__RSC_SERVER_MANIFEST)
Expand Down Expand Up @@ -70,7 +69,6 @@ const render = getRender({
error500Mod,
Document,
buildManifest,
prerenderManifest,
renderToHTML,
reactLoadableManifest,
clientReferenceManifest: isServerComponent ? rscManifest : null,
Expand Down
2 changes: 0 additions & 2 deletions packages/next/src/build/templates/edge-ssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ const error500Mod = userland500Page
const maybeJSONParse = (str?: string) => (str ? JSON.parse(str) : undefined)

const buildManifest: BuildManifest = self.__BUILD_MANIFEST as any
const prerenderManifest = maybeJSONParse(self.__PRERENDER_MANIFEST)
const reactLoadableManifest = maybeJSONParse(self.__REACT_LOADABLE_MANIFEST)
const subresourceIntegrityManifest = sriEnabled
? maybeJSONParse(self.__SUBRESOURCE_INTEGRITY_MANIFEST)
Expand All @@ -99,7 +98,6 @@ const render = getRender({
error500Mod,
Document,
buildManifest,
prerenderManifest,
renderToHTML,
reactLoadableManifest,
subresourceIntegrityManifest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ import {
WebNextResponse,
} from '../../../../server/base-http/web'
import { SERVER_RUNTIME } from '../../../../lib/constants'
import type { ManifestRewriteRoute, PrerenderManifest } from '../../..'
import type { ManifestRewriteRoute } from '../../..'
import { normalizeAppPath } from '../../../../shared/lib/router/utils/app-paths'
import type { SizeLimit } from '../../../../types'
import { internal_getCurrentFunctionWaitUntil } from '../../../../server/web/internal-edge-wait-until'
import type { PAGE_TYPES } from '../../../../lib/page-types'
import type { NextRequestHint } from '../../../../server/web/adapter'
import type { DeepReadonly } from '../../../../shared/lib/deep-readonly'
import { getEdgePreviewProps } from '../../../../server/web/get-edge-preview-props'

export function getRender({
dev,
Expand All @@ -32,7 +30,6 @@ export function getRender({
pagesType,
Document,
buildManifest,
prerenderManifest,
reactLoadableManifest,
interceptionRouteRewrites,
renderToHTML,
Expand All @@ -55,7 +52,6 @@ export function getRender({
renderToHTML?: any
Document: DocumentType
buildManifest: BuildManifest
prerenderManifest: DeepReadonly<PrerenderManifest>
reactLoadableManifest: ReactLoadableManifest
subresourceIntegrityManifest?: Record<string, string>
interceptionRouteRewrites?: ManifestRewriteRoute[]
Expand Down Expand Up @@ -89,12 +85,6 @@ export function getRender({
page,
pathname: isAppPath ? normalizeAppPath(page) : page,
pagesType,
prerenderManifest: prerenderManifest
? {
...prerenderManifest,
preview: getEdgePreviewProps(),
}
: undefined,
interceptionRouteRewrites,
extendRenderOpts: {
buildId,
Expand Down
5 changes: 0 additions & 5 deletions packages/next/src/build/webpack/plugins/middleware-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
SUBRESOURCE_INTEGRITY_MANIFEST,
NEXT_FONT_MANIFEST,
SERVER_REFERENCE_MANIFEST,
PRERENDER_MANIFEST,
INTERCEPTION_ROUTE_REWRITE_MANIFEST,
} from '../../../shared/lib/constants'
import type { MiddlewareConfig } from '../../analysis/get-page-static-info'
Expand Down Expand Up @@ -138,10 +137,6 @@ function getEntryFiles(
files.push(`server/edge-${INSTRUMENTATION_HOOK_FILENAME}.js`)
}

if (process.env.NODE_ENV === 'production') {
files.push(PRERENDER_MANIFEST.replace('json', 'js'))
}

files.push(
...entryFiles
.filter((file) => !file.endsWith('.hot-update.js'))
Expand Down
1 change: 0 additions & 1 deletion packages/next/src/client/route-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ declare global {
__BUILD_MANIFEST_CB?: Function
__MIDDLEWARE_MATCHERS?: MiddlewareMatcher[]
__MIDDLEWARE_MANIFEST_CB?: Function
__PRERENDER_MANIFEST?: string
__REACT_LOADABLE_MANIFEST?: any
__RSC_MANIFEST?: any
__RSC_SERVER_MANIFEST?: any
Expand Down
19 changes: 6 additions & 13 deletions packages/next/src/server/web-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type RenderResult from './render-result'
import type { NextParsedUrlQuery, NextUrlWithParsedQuery } from './request-meta'
import type { Params } from '../shared/lib/router/utils/route-matcher'
import type { LoadComponentsReturnType } from './load-components'
import type { PrerenderManifest } from '../build'
import type {
LoadedRenderOpts,
MiddlewareRoutingItem,
Expand Down Expand Up @@ -33,7 +32,6 @@ import type { PAGE_TYPES } from '../lib/page-types'
import type { Rewrite } from '../lib/load-custom-routes'
import { buildCustomRoute } from '../lib/build-custom-route'
import { UNDERSCORE_NOT_FOUND_ROUTE } from '../api/constants'
import type { DeepReadonly } from '../shared/lib/deep-readonly'
import { getEdgeInstrumentationModule } from './web/globals'
import type { ServerOnInstrumentationRequestError } from './app-render/types'
import { getEdgePreviewProps } from './web/get-edge-preview-props'
Expand All @@ -52,7 +50,6 @@ interface WebServerOptions extends Options {
| typeof import('./app-render/app-render').renderToHTMLOrFlight
| undefined
incrementalCacheHandler?: any
prerenderManifest: DeepReadonly<PrerenderManifest> | undefined
interceptionRouteRewrites?: Rewrite[]
}
}
Expand Down Expand Up @@ -140,17 +137,13 @@ export default class NextWebServer extends BaseServer<
}

protected getPrerenderManifest() {
const { prerenderManifest } = this.serverOptions.webServerConfig
if (this.renderOpts?.dev || !prerenderManifest) {
return {
version: -1 as any, // letting us know this doesn't conform to spec
routes: {},
dynamicRoutes: {},
notFoundRoutes: [],
preview: getEdgePreviewProps(),
}
return {
version: -1 as any, // letting us know this doesn't conform to spec
routes: {},
dynamicRoutes: {},
notFoundRoutes: [],
preview: getEdgePreviewProps(),
}
return prerenderManifest
}

protected getNextFontManifest() {
Expand Down
6 changes: 0 additions & 6 deletions test/e2e/app-dir/app/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ describe('app dir - basic', () => {
)
})

it('should not have entire prerender-manifest for edge', async () => {
expect(await next.readFile('.next/prerender-manifest.js')).not.toContain(
'initialRevalidate'
)
})

if (!process.env.NEXT_EXPERIMENTAL_COMPILE) {
it('should have correct size in build output', async () => {
expect(next.cliOutput).toMatch(
Expand Down
1 change: 0 additions & 1 deletion test/e2e/middleware-trailing-slash/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ describe('Middleware Runtime trailing slash', () => {
delete middlewareWithoutEnvs.env
expect(middlewareWithoutEnvs).toEqual({
files: expect.arrayContaining([
'prerender-manifest.js',
'server/edge-runtime-webpack.js',
'server/middleware.js',
]),
Expand Down
Loading