From 38d08e27f09a06820b573c8ff5ef2eff6c39c5cb Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Tue, 16 Jul 2024 10:42:18 +0200 Subject: [PATCH] Drop edge prerender manifest (#67787) ### What Follow up for #67779 , we don't have to generate the edge preview manifest since it's mainly for rendering the preview props and now preview props can be accessed through process env by a util `getEdgePreviewProps()` --- packages/next/src/build/index.ts | 29 ------------------- .../next/src/build/templates/edge-ssr-app.ts | 2 -- packages/next/src/build/templates/edge-ssr.ts | 2 -- .../loaders/next-edge-ssr-loader/render.ts | 12 +------- .../webpack/plugins/middleware-plugin.ts | 5 ---- packages/next/src/client/route-loader.ts | 1 - packages/next/src/server/web-server.ts | 19 ++++-------- test/e2e/app-dir/app/index.test.ts | 6 ---- .../test/index.test.ts | 1 - 9 files changed, 7 insertions(+), 70 deletions(-) diff --git a/packages/next/src/build/index.ts b/packages/next/src/build/index.ts index dfb700ba86fb5..a85601b5332ea 100644 --- a/packages/next/src/build/index.ts +++ b/packages/next/src/build/index.ts @@ -342,32 +342,6 @@ async function writePrerenderManifest( manifest: DeepReadonly ): Promise { await writeManifest(path.join(distDir, PRERENDER_MANIFEST), manifest) - await writeEdgePartialPrerenderManifest(distDir, manifest) -} - -async function writeEdgePartialPrerenderManifest( - distDir: string, - manifest: DeepReadonly> -): Promise { - // 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> = - { - 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( @@ -1215,8 +1189,6 @@ export default async function build( '{"type": "commonjs"}' ) - await writeEdgePartialPrerenderManifest(distDir, {}) - const outputFileTracingRoot = config.experimental.outputFileTracingRoot || dir @@ -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( diff --git a/packages/next/src/build/templates/edge-ssr-app.ts b/packages/next/src/build/templates/edge-ssr-app.ts index 195f9d1726de1..b9bde515d3851 100644 --- a/packages/next/src/build/templates/edge-ssr-app.ts +++ b/packages/next/src/build/templates/edge-ssr-app.ts @@ -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) @@ -70,7 +69,6 @@ const render = getRender({ error500Mod, Document, buildManifest, - prerenderManifest, renderToHTML, reactLoadableManifest, clientReferenceManifest: isServerComponent ? rscManifest : null, diff --git a/packages/next/src/build/templates/edge-ssr.ts b/packages/next/src/build/templates/edge-ssr.ts index 953fc69eeb80c..dbed6d7b9e870 100644 --- a/packages/next/src/build/templates/edge-ssr.ts +++ b/packages/next/src/build/templates/edge-ssr.ts @@ -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) @@ -99,7 +98,6 @@ const render = getRender({ error500Mod, Document, buildManifest, - prerenderManifest, renderToHTML, reactLoadableManifest, subresourceIntegrityManifest, diff --git a/packages/next/src/build/webpack/loaders/next-edge-ssr-loader/render.ts b/packages/next/src/build/webpack/loaders/next-edge-ssr-loader/render.ts index 0aef8778a5508..8d3ab77ad9cd9 100644 --- a/packages/next/src/build/webpack/loaders/next-edge-ssr-loader/render.ts +++ b/packages/next/src/build/webpack/loaders/next-edge-ssr-loader/render.ts @@ -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, @@ -32,7 +30,6 @@ export function getRender({ pagesType, Document, buildManifest, - prerenderManifest, reactLoadableManifest, interceptionRouteRewrites, renderToHTML, @@ -55,7 +52,6 @@ export function getRender({ renderToHTML?: any Document: DocumentType buildManifest: BuildManifest - prerenderManifest: DeepReadonly reactLoadableManifest: ReactLoadableManifest subresourceIntegrityManifest?: Record interceptionRouteRewrites?: ManifestRewriteRoute[] @@ -89,12 +85,6 @@ export function getRender({ page, pathname: isAppPath ? normalizeAppPath(page) : page, pagesType, - prerenderManifest: prerenderManifest - ? { - ...prerenderManifest, - preview: getEdgePreviewProps(), - } - : undefined, interceptionRouteRewrites, extendRenderOpts: { buildId, diff --git a/packages/next/src/build/webpack/plugins/middleware-plugin.ts b/packages/next/src/build/webpack/plugins/middleware-plugin.ts index e6bdccd6da88e..54dfd9938fc07 100644 --- a/packages/next/src/build/webpack/plugins/middleware-plugin.ts +++ b/packages/next/src/build/webpack/plugins/middleware-plugin.ts @@ -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' @@ -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')) diff --git a/packages/next/src/client/route-loader.ts b/packages/next/src/client/route-loader.ts index ab0337eff033f..133dae84dec1f 100644 --- a/packages/next/src/client/route-loader.ts +++ b/packages/next/src/client/route-loader.ts @@ -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 diff --git a/packages/next/src/server/web-server.ts b/packages/next/src/server/web-server.ts index ea55846c2e5b7..92e23b56a5a49 100644 --- a/packages/next/src/server/web-server.ts +++ b/packages/next/src/server/web-server.ts @@ -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, @@ -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' @@ -52,7 +50,6 @@ interface WebServerOptions extends Options { | typeof import('./app-render/app-render').renderToHTMLOrFlight | undefined incrementalCacheHandler?: any - prerenderManifest: DeepReadonly | undefined interceptionRouteRewrites?: Rewrite[] } } @@ -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() { diff --git a/test/e2e/app-dir/app/index.test.ts b/test/e2e/app-dir/app/index.test.ts index 2bf71f0ffcb0b..00879c8e87ef2 100644 --- a/test/e2e/app-dir/app/index.test.ts +++ b/test/e2e/app-dir/app/index.test.ts @@ -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( diff --git a/test/e2e/middleware-trailing-slash/test/index.test.ts b/test/e2e/middleware-trailing-slash/test/index.test.ts index 1ee913f5a5578..5e5295ede8e2c 100644 --- a/test/e2e/middleware-trailing-slash/test/index.test.ts +++ b/test/e2e/middleware-trailing-slash/test/index.test.ts @@ -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', ]),