Unverified Commit 1255e199 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Reorganize client references manifest (#46777)

* Rename client reference plugins from `Flight*` to `ClientReference*`
* Rename `serverComponentManifest` to `clientReferenceManifest`
* Group the key/value in client reference manifest
* Update turbopack crates
parent 53f29cd6
...@@ -22,8 +22,8 @@ declare global { ...@@ -22,8 +22,8 @@ declare global {
import type { Ipc } from "@vercel/turbopack-next/ipc/index"; import type { Ipc } from "@vercel/turbopack-next/ipc/index";
import type { IncomingMessage, ServerResponse } from "node:http"; import type { IncomingMessage, ServerResponse } from "node:http";
import type { import type {
FlightCSSManifest, ClientCSSReferenceManifest,
FlightManifest, ClientReferenceManifest,
} from "next/dist/build/webpack/plugins/flight-manifest-plugin"; } from "next/dist/build/webpack/plugins/flight-manifest-plugin";
import type { RenderData } from "types/turbopack"; import type { RenderData } from "types/turbopack";
import type { RenderOpts } from "next/dist/server/app-render/types"; import type { RenderOpts } from "next/dist/server/app-render/types";
...@@ -107,13 +107,6 @@ type LoaderTree = [ ...@@ -107,13 +107,6 @@ type LoaderTree = [
components: ComponentsType components: ComponentsType
]; ];
type ServerComponentsManifest = {
[id: string]: ServerComponentsManifestModule;
};
type ServerComponentsManifestModule = {
[exportName: string]: { id: string; chunks: string[]; name: string };
};
async function runOperation(renderData: RenderData) { async function runOperation(renderData: RenderData) {
const layoutInfoChunks: Record<string, string[]> = {}; const layoutInfoChunks: Record<string, string[]> = {};
const pageItem = LAYOUT_INFO[LAYOUT_INFO.length - 1]; const pageItem = LAYOUT_INFO[LAYOUT_INFO.length - 1];
...@@ -140,74 +133,83 @@ async function runOperation(renderData: RenderData) { ...@@ -140,74 +133,83 @@ async function runOperation(renderData: RenderData) {
const proxyMethodsForModule = ( const proxyMethodsForModule = (
id: string id: string
): ProxyHandler<FlightManifest["__ssr_module_mapping__"][""]> => ({ ): ProxyHandler<ClientReferenceManifest["ssrModuleMapping"]> => {
get(_target, name) { return {
return { get(_target, prop: string) {
id, return {
chunks: JSON.parse(id)[1], id,
name, chunks: JSON.parse(id)[1],
}; name: prop,
}, };
}); },
const proxyMethodsNested = (): ProxyHandler< };
FlightManifest["__ssr_module_mapping__"] }
const proxyMethodsNested = (type: "ssrModuleMapping" | "clientModules"): ProxyHandler<
ClientReferenceManifest["ssrModuleMapping"] | ClientReferenceManifest["clientModules"]
> => { > => {
return { return {
get(target, name, receiver) { get(_target, key: string) {
if (name === "__ssr_module_mapping__") { if (type === "ssrModuleMapping") {
return manifest; return new Proxy({}, proxyMethodsForModule(key as string));
} }
if (name === "__entry_css_files__") { if (type === "clientModules") {
return __entry_css_files__; // The key is a `${file}#${name}`, but `file` can contain `#` itself.
// There are 2 possibilities:
// "file#" => id = "file", name = ""
// "file#foo" => id = "file", name = "foo"
const pos = key.lastIndexOf("#");
let id = key;
let name = "";
if (pos !== -1) {
id = key.slice(0, pos);
name = key.slice(pos + 1);
} else {
throw new Error("key need to be in format of ${file}#${name}");
}
return {
id,
name,
chunks: JSON.parse(id)[1],
};
} }
return new Proxy({}, proxyMethodsForModule(name as string));
}, },
}; };
}; };
const proxyMethods = (): ProxyHandler<FlightManifest> => {
const proxyMethods = (): ProxyHandler<ClientReferenceManifest> => {
const clientModulesProxy = new Proxy({}, proxyMethodsNested("clientModules"));
const ssrModuleMappingProxy = new Proxy({}, proxyMethodsNested("ssrModuleMapping"));
return { return {
get(_target, key: string) { get(_target: any, prop: string) {
if (key === "__ssr_module_mapping__") { if (prop === "ssrModuleMapping") {
return new Proxy({} as any, proxyMethodsNested()); return ssrModuleMappingProxy;
} }
if (key === "__entry_css_files__") { if (prop === "clientModules") {
return __entry_css_files__; return clientModulesProxy;
} }
if (prop === "cssFiles") {
// The key is a `${file}#${name}`, but `file` can contain `#` itself. return cssFiles;
// There are 2 possibilities:
// "file#" => id = "file", name = ""
// "file#foo" => id = "file", name = "foo"
const pos = key.lastIndexOf("#");
let id = key;
let name = "";
if (pos === -1) {
throw new Error("key need to be in format of ${file}#${name}");
} else {
id = key.slice(0, pos);
name = key.slice(pos + 1);
} }
return {
id,
name,
chunks: JSON.parse(id)[1],
};
}, },
}; };
}; };
const manifest: FlightManifest = new Proxy({} as any, proxyMethods()); const manifest: ClientReferenceManifest = new Proxy({} as any, proxyMethods());
const serverCSSManifest: FlightCSSManifest = {}; const serverCSSManifest: ClientCSSReferenceManifest = {
const __entry_css_files__: FlightManifest["__entry_css_files__"] = {}; cssImports: {},
cssModules: {},
};
const cssFiles: ClientReferenceManifest["cssFiles"] = {};
for (const [key, chunks] of Object.entries(layoutInfoChunks)) { for (const [key, chunks] of Object.entries(layoutInfoChunks)) {
const cssChunks = chunks.filter((path) => path.endsWith(".css")); const cssChunks = chunks.filter((path) => path.endsWith(".css"));
serverCSSManifest[`${key}.js`] = cssChunks.map((chunk) => serverCSSManifest.cssImports[`${key}.js`] = cssChunks.map((chunk) =>
JSON.stringify([chunk, [chunk]]) JSON.stringify([chunk, [chunk]])
); );
__entry_css_files__[key] = cssChunks; cssFiles[key] = cssChunks;
} }
serverCSSManifest.__entry_css_mods__ = { serverCSSManifest.cssModules = {
page: serverCSSManifest["page.js"], page: serverCSSManifest.cssImports["page.js"],
}; };
const req: IncomingMessage = { const req: IncomingMessage = {
url: renderData.url, url: renderData.url,
...@@ -244,7 +246,7 @@ async function runOperation(renderData: RenderData) { ...@@ -244,7 +246,7 @@ async function runOperation(renderData: RenderData) {
tree, tree,
pages: ["page.js"], pages: ["page.js"],
}, },
serverComponentManifest: manifest, clientReferenceManifest: manifest,
serverCSSManifest, serverCSSManifest,
runtime: "nodejs", runtime: "nodejs",
serverComponents: true, serverComponents: true,
......
export function isClientReference(reference: any): boolean {
return reference?.$$typeof === Symbol.for('react.client.reference')
}
...@@ -54,7 +54,7 @@ import { ...@@ -54,7 +54,7 @@ import {
loadRequireHook, loadRequireHook,
overrideBuiltInReactPackages, overrideBuiltInReactPackages,
} from './webpack/require-hook' } from './webpack/require-hook'
import { isClientReference } from './is-client-reference' import { isClientReference } from '../lib/client-reference'
import { StaticGenerationAsyncStorageWrapper } from '../server/async-storage/static-generation-async-storage-wrapper' import { StaticGenerationAsyncStorageWrapper } from '../server/async-storage/static-generation-async-storage-wrapper'
import { IncrementalCache } from '../server/lib/incremental-cache' import { IncrementalCache } from '../server/lib/incremental-cache'
import { patchFetch } from '../server/lib/patch-fetch' import { patchFetch } from '../server/lib/patch-fetch'
......
...@@ -46,8 +46,8 @@ import { ReactLoadablePlugin } from './webpack/plugins/react-loadable-plugin' ...@@ -46,8 +46,8 @@ import { ReactLoadablePlugin } from './webpack/plugins/react-loadable-plugin'
import { WellKnownErrorsPlugin } from './webpack/plugins/wellknown-errors-plugin' import { WellKnownErrorsPlugin } from './webpack/plugins/wellknown-errors-plugin'
import { regexLikeCss } from './webpack/config/blocks/css' import { regexLikeCss } from './webpack/config/blocks/css'
import { CopyFilePlugin } from './webpack/plugins/copy-file-plugin' import { CopyFilePlugin } from './webpack/plugins/copy-file-plugin'
import { FlightManifestPlugin } from './webpack/plugins/flight-manifest-plugin' import { ClientReferenceManifestPlugin } from './webpack/plugins/flight-manifest-plugin'
import { FlightClientEntryPlugin } from './webpack/plugins/flight-client-entry-plugin' import { ClientReferenceEntryPlugin } from './webpack/plugins/flight-client-entry-plugin'
import { NextTypesPlugin } from './webpack/plugins/next-types-plugin' import { NextTypesPlugin } from './webpack/plugins/next-types-plugin'
import type { import type {
Feature, Feature,
...@@ -2224,11 +2224,11 @@ export default async function getBaseWebpackConfig( ...@@ -2224,11 +2224,11 @@ export default async function getBaseWebpackConfig(
hasAppDir && isClient && new AppBuildManifestPlugin({ dev }), hasAppDir && isClient && new AppBuildManifestPlugin({ dev }),
hasServerComponents && hasServerComponents &&
(isClient (isClient
? new FlightManifestPlugin({ ? new ClientReferenceManifestPlugin({
dev, dev,
appDir, appDir,
}) })
: new FlightClientEntryPlugin({ : new ClientReferenceEntryPlugin({
appDir, appDir,
dev, dev,
isEdgeServer, isEdgeServer,
......
...@@ -149,7 +149,7 @@ export default async function edgeSSRLoader(this: any) { ...@@ -149,7 +149,7 @@ export default async function edgeSSRLoader(this: any) {
appRenderToHTML, appRenderToHTML,
pagesRenderToHTML, pagesRenderToHTML,
reactLoadableManifest, reactLoadableManifest,
serverComponentManifest: ${isServerComponent} ? rscManifest : null, clientReferenceManifest: ${isServerComponent} ? rscManifest : null,
serverCSSManifest: ${isServerComponent} ? rscCssManifest : null, serverCSSManifest: ${isServerComponent} ? rscCssManifest : null,
serverActionsManifest: ${isServerComponent} ? rscServerManifest : null, serverActionsManifest: ${isServerComponent} ? rscServerManifest : null,
subresourceIntegrityManifest, subresourceIntegrityManifest,
......
...@@ -3,6 +3,7 @@ import type { NextConfigComplete } from '../../../../server/config-shared' ...@@ -3,6 +3,7 @@ import type { NextConfigComplete } from '../../../../server/config-shared'
import type { DocumentType, AppType } from '../../../../shared/lib/utils' import type { DocumentType, AppType } from '../../../../shared/lib/utils'
import type { BuildManifest } from '../../../../server/get-page-files' import type { BuildManifest } from '../../../../server/get-page-files'
import type { ReactLoadableManifest } from '../../../../server/load-components' import type { ReactLoadableManifest } from '../../../../server/load-components'
import type { ClientReferenceManifest } from '../../plugins/flight-manifest-plugin'
import type { NextFontManifestPlugin } from '../../plugins/next-font-manifest-plugin' import type { NextFontManifestPlugin } from '../../plugins/next-font-manifest-plugin'
import WebServer from '../../../../server/web-server' import WebServer from '../../../../server/web-server'
...@@ -25,7 +26,7 @@ export function getRender({ ...@@ -25,7 +26,7 @@ export function getRender({
reactLoadableManifest, reactLoadableManifest,
appRenderToHTML, appRenderToHTML,
pagesRenderToHTML, pagesRenderToHTML,
serverComponentManifest, clientReferenceManifest,
subresourceIntegrityManifest, subresourceIntegrityManifest,
serverCSSManifest, serverCSSManifest,
serverActionsManifest, serverActionsManifest,
...@@ -47,7 +48,7 @@ export function getRender({ ...@@ -47,7 +48,7 @@ export function getRender({
buildManifest: BuildManifest buildManifest: BuildManifest
reactLoadableManifest: ReactLoadableManifest reactLoadableManifest: ReactLoadableManifest
subresourceIntegrityManifest?: Record<string, string> subresourceIntegrityManifest?: Record<string, string>
serverComponentManifest: any clientReferenceManifest?: ClientReferenceManifest
serverCSSManifest: any serverCSSManifest: any
serverActionsManifest: any serverActionsManifest: any
appServerMod: any appServerMod: any
...@@ -79,7 +80,7 @@ export function getRender({ ...@@ -79,7 +80,7 @@ export function getRender({
runtime: SERVER_RUNTIME.experimentalEdge, runtime: SERVER_RUNTIME.experimentalEdge,
supportsDynamicHTML: true, supportsDynamicHTML: true,
disableOptimizedLoading: true, disableOptimizedLoading: true,
serverComponentManifest, clientReferenceManifest,
serverCSSManifest, serverCSSManifest,
serverActionsManifest, serverActionsManifest,
}, },
......
...@@ -3,7 +3,7 @@ import type { ...@@ -3,7 +3,7 @@ import type {
ClientComponentImports, ClientComponentImports,
NextFlightClientEntryLoaderOptions, NextFlightClientEntryLoaderOptions,
} from '../loaders/next-flight-client-entry-loader' } from '../loaders/next-flight-client-entry-loader'
import type { FlightCSSManifest } from './flight-manifest-plugin' import type { ClientCSSReferenceManifest } from './flight-manifest-plugin'
import { webpack } from 'next/dist/compiled/webpack/webpack' import { webpack } from 'next/dist/compiled/webpack/webpack'
import { stringify } from 'querystring' import { stringify } from 'querystring'
...@@ -56,8 +56,8 @@ const pluginState = getProxiedPluginState({ ...@@ -56,8 +56,8 @@ const pluginState = getProxiedPluginState({
actionModId: {} as Record<string, string | number>, actionModId: {} as Record<string, string | number>,
// Manifest of CSS entry files for server/edge server. // Manifest of CSS entry files for server/edge server.
serverCSSManifest: {} as FlightCSSManifest, serverCSSManifest: {} as ClientCSSReferenceManifest,
edgeServerCSSManifest: {} as FlightCSSManifest, edgeServerCSSManifest: {} as ClientCSSReferenceManifest,
// Mapping of resource path to module id for server/edge server. // Mapping of resource path to module id for server/edge server.
serverModuleIds: {} as Record<string, string | number>, serverModuleIds: {} as Record<string, string | number>,
...@@ -71,7 +71,7 @@ const pluginState = getProxiedPluginState({ ...@@ -71,7 +71,7 @@ const pluginState = getProxiedPluginState({
injectedClientEntries: {} as Record<string, string>, injectedClientEntries: {} as Record<string, string>,
}) })
export class FlightClientEntryPlugin { export class ClientReferenceEntryPlugin {
dev: boolean dev: boolean
appDir: string appDir: string
isEdgeServer: boolean isEdgeServer: boolean
...@@ -378,12 +378,10 @@ export class FlightClientEntryPlugin { ...@@ -378,12 +378,10 @@ export class FlightClientEntryPlugin {
} }
const entryCSSInfo: Record<string, string[]> = const entryCSSInfo: Record<string, string[]> =
cssManifest.__entry_css_mods__ || {} cssManifest.cssModules || {}
entryCSSInfo[entryName] = [...cssImportsForChunk[entryName]] entryCSSInfo[entryName] = [...cssImportsForChunk[entryName]]
Object.assign(cssManifest, { cssManifest.cssModules = entryCSSInfo
__entry_css_mods__: entryCSSInfo,
})
}) })
}) })
...@@ -408,7 +406,8 @@ export class FlightClientEntryPlugin { ...@@ -408,7 +406,8 @@ export class FlightClientEntryPlugin {
clientEntryDependencyMap, clientEntryDependencyMap,
}) })
Object.assign(cssManifest, cssImports) if (!cssManifest.cssImports) cssManifest.cssImports = {}
Object.assign(cssManifest.cssImports, cssImports)
} }
}) })
}) })
...@@ -421,18 +420,17 @@ export class FlightClientEntryPlugin { ...@@ -421,18 +420,17 @@ export class FlightClientEntryPlugin {
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_HASH, stage: webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_HASH,
}, },
(assets: webpack.Compilation['assets']) => { (assets: webpack.Compilation['assets']) => {
const manifest = JSON.stringify( const data: ClientCSSReferenceManifest = {
{ cssImports: {
...pluginState.serverCSSManifest, ...pluginState.serverCSSManifest.cssImports,
...pluginState.edgeServerCSSManifest, ...pluginState.edgeServerCSSManifest.cssImports,
__entry_css_mods__: {
...pluginState.serverCSSManifest.__entry_css_mods__,
...pluginState.edgeServerCSSManifest.__entry_css_mods__,
},
}, },
null, cssModules: {
this.dev ? 2 : undefined ...pluginState.serverCSSManifest.cssModules,
) ...pluginState.edgeServerCSSManifest.cssModules,
},
}
const manifest = JSON.stringify(data, null, this.dev ? 2 : undefined)
assets[FLIGHT_SERVER_CSS_MANIFEST + '.json'] = new sources.RawSource( assets[FLIGHT_SERVER_CSS_MANIFEST + '.json'] = new sources.RawSource(
manifest manifest
) as unknown as webpack.sources.RawSource ) as unknown as webpack.sources.RawSource
......
...@@ -18,6 +18,7 @@ import { getProxiedPluginState } from '../../build-context' ...@@ -18,6 +18,7 @@ import { getProxiedPluginState } from '../../build-context'
import { traverseModules } from '../utils' import { traverseModules } from '../utils'
import { nonNullable } from '../../../lib/non-nullable' import { nonNullable } from '../../../lib/non-nullable'
import { WEBPACK_LAYERS } from '../../../lib/constants' import { WEBPACK_LAYERS } from '../../../lib/constants'
import { getClientReferenceModuleKey } from '../../../lib/client-reference'
interface Options { interface Options {
dev: boolean dev: boolean
...@@ -38,7 +39,7 @@ const pluginState = getProxiedPluginState({ ...@@ -38,7 +39,7 @@ const pluginState = getProxiedPluginState({
ASYNC_CLIENT_MODULES: [] as string[], ASYNC_CLIENT_MODULES: [] as string[],
}) })
interface ManifestNode { export interface ManifestNode {
[moduleExport: string]: { [moduleExport: string]: {
/** /**
* Webpack module id * Webpack module id
...@@ -60,29 +61,31 @@ interface ManifestNode { ...@@ -60,29 +61,31 @@ interface ManifestNode {
} }
} }
export type FlightManifest = { export type ClientReferenceManifest = {
__ssr_module_mapping__: { clientModules: ManifestNode
[modulePath: string]: ManifestNode ssrModuleMapping: {
[moduleId: string]: ManifestNode
} }
__edge_ssr_module_mapping__: { edgeSSRModuleMapping: {
[modulePath: string]: ManifestNode [moduleId: string]: ManifestNode
} }
__entry_css_files__: { cssFiles: {
[entryPathWithoutExtension: string]: string[] [entryPathWithoutExtension: string]: string[]
} }
} & ManifestNode }
export type FlightCSSManifest = { export type ClientCSSReferenceManifest = {
[modulePath: string]: string[] cssImports: {
} & { [modulePath: string]: string[]
__entry_css_mods__?: { }
cssModules?: {
[entry: string]: string[] [entry: string]: string[]
} }
} }
const PLUGIN_NAME = 'FlightManifestPlugin' const PLUGIN_NAME = 'ClientReferenceManifestPlugin'
export class FlightManifestPlugin { export class ClientReferenceManifestPlugin {
dev: Options['dev'] = false dev: Options['dev'] = false
appDir: Options['appDir'] appDir: Options['appDir']
ASYNC_CLIENT_MODULES: Set<string> ASYNC_CLIENT_MODULES: Set<string>
...@@ -126,11 +129,11 @@ export class FlightManifestPlugin { ...@@ -126,11 +129,11 @@ export class FlightManifestPlugin {
compilation: webpack.Compilation, compilation: webpack.Compilation,
context: string context: string
) { ) {
// @ts-ignore const manifest: ClientReferenceManifest = {
const manifest: FlightManifest = { ssrModuleMapping: {},
__ssr_module_mapping__: {}, edgeSSRModuleMapping: {},
__edge_ssr_module_mapping__: {}, cssFiles: {},
__entry_css_files__: {}, clientModules: {},
} }
const dev = this.dev const dev = this.dev
...@@ -183,8 +186,9 @@ export class FlightManifestPlugin { ...@@ -183,8 +186,9 @@ export class FlightManifestPlugin {
return return
} }
const moduleIdMapping = manifest.__ssr_module_mapping__ const moduleReferences = manifest.clientModules
const edgeModuleIdMapping = manifest.__edge_ssr_module_mapping__ const moduleIdMapping = manifest.ssrModuleMapping
const edgeModuleIdMapping = manifest.edgeSSRModuleMapping
// Note that this isn't that reliable as webpack is still possible to assign // Note that this isn't that reliable as webpack is still possible to assign
// additional queries to make sure there's no conflict even using the `named` // additional queries to make sure there's no conflict even using the `named`
...@@ -198,18 +202,19 @@ export class FlightManifestPlugin { ...@@ -198,18 +202,19 @@ export class FlightManifestPlugin {
ssrNamedModuleId = `./${ssrNamedModuleId.replace(/\\/g, '/')}` ssrNamedModuleId = `./${ssrNamedModuleId.replace(/\\/g, '/')}`
if (isCSSModule) { if (isCSSModule) {
if (!manifest[resource + '#']) { const exportName = getClientReferenceModuleKey(resource, '')
manifest[resource + '#'] = { if (!moduleReferences[exportName]) {
moduleReferences[exportName] = {
id: id || '', id: id || '',
name: '', name: 'default',
chunks: chunkCSS, chunks: chunkCSS,
} }
} else { } else {
// It is possible that there are multiple modules with the same resource, // It is possible that there are multiple modules with the same resource,
// e.g. extracted by mini-css-extract-plugin. In that case we need to // e.g. extracted by mini-css-extract-plugin. In that case we need to
// merge the chunks. // merge the chunks.
manifest[resource + '#'].chunks = [ moduleReferences[exportName].chunks = [
...new Set([...manifest[resource + '#'].chunks, ...chunkCSS]), ...new Set([...moduleReferences[exportName].chunks, ...chunkCSS]),
] ]
} }
...@@ -279,48 +284,31 @@ export class FlightManifestPlugin { ...@@ -279,48 +284,31 @@ export class FlightManifestPlugin {
: null : null
function addClientReference(name: string) { function addClientReference(name: string) {
if (name === '*') { const exportName = getClientReferenceModuleKey(resource, name)
manifest[resource] = { manifest.clientModules[exportName] = {
id, id,
chunks: requiredChunks, name,
name: '*', chunks: requiredChunks,
async: isAsyncModule, async: isAsyncModule,
} }
if (esmResource) { if (esmResource) {
manifest[esmResource] = manifest[resource] const edgeExportName = getClientReferenceModuleKey(
} esmResource,
} else if (name === '') { name
manifest[resource + '#'] = { )
id, manifest.clientModules[edgeExportName] =
chunks: requiredChunks, manifest.clientModules[exportName]
name: '',
async: isAsyncModule,
}
if (esmResource) {
manifest[esmResource + '#'] = manifest[resource + '#']
}
} else {
manifest[resource + '#' + name] = {
id,
chunks: requiredChunks,
name,
async: isAsyncModule,
}
if (esmResource) {
manifest[esmResource + '#' + name] =
manifest[resource + '#' + name]
}
} }
} }
function addSSRIdMapping(name: string) { function addSSRIdMapping(name: string) {
const key = resource + (name === '*' ? '' : '#' + name) const exportName = getClientReferenceModuleKey(resource, name)
if ( if (
typeof pluginState.serverModuleIds[ssrNamedModuleId] !== 'undefined' typeof pluginState.serverModuleIds[ssrNamedModuleId] !== 'undefined'
) { ) {
moduleIdMapping[id] = moduleIdMapping[id] || {} moduleIdMapping[id] = moduleIdMapping[id] || {}
moduleIdMapping[id][name] = { moduleIdMapping[id][name] = {
...manifest[key], ...manifest.clientModules[exportName],
id: pluginState.serverModuleIds[ssrNamedModuleId], id: pluginState.serverModuleIds[ssrNamedModuleId],
} }
} }
...@@ -331,7 +319,7 @@ export class FlightManifestPlugin { ...@@ -331,7 +319,7 @@ export class FlightManifestPlugin {
) { ) {
edgeModuleIdMapping[id] = edgeModuleIdMapping[id] || {} edgeModuleIdMapping[id] = edgeModuleIdMapping[id] || {}
edgeModuleIdMapping[id][name] = { edgeModuleIdMapping[id][name] = {
...manifest[key], ...manifest.clientModules[exportName],
id: pluginState.edgeServerModuleIds[ssrNamedModuleId], id: pluginState.edgeServerModuleIds[ssrNamedModuleId],
} }
} }
...@@ -355,7 +343,7 @@ export class FlightManifestPlugin { ...@@ -355,7 +343,7 @@ export class FlightManifestPlugin {
// If the chunk is from `app/` chunkGroup, use it first. // If the chunk is from `app/` chunkGroup, use it first.
// This make sure not to load the overlapped chunk from `pages/` chunkGroup // This make sure not to load the overlapped chunk from `pages/` chunkGroup
if ( if (
!manifest[key] || !manifest.clientModules[key] ||
(chunkGroup.name && /^app[\\/]/.test(chunkGroup.name)) (chunkGroup.name && /^app[\\/]/.test(chunkGroup.name))
) { ) {
addClientReference(name) addClientReference(name)
...@@ -364,8 +352,9 @@ export class FlightManifestPlugin { ...@@ -364,8 +352,9 @@ export class FlightManifestPlugin {
addSSRIdMapping(name) addSSRIdMapping(name)
}) })
manifest.__ssr_module_mapping__ = moduleIdMapping manifest.clientModules = moduleReferences
manifest.__edge_ssr_module_mapping__ = edgeModuleIdMapping manifest.ssrModuleMapping = moduleIdMapping
manifest.edgeSSRModuleMapping = edgeModuleIdMapping
} }
chunkGroup.chunks.forEach((chunk: webpack.Chunk) => { chunkGroup.chunks.forEach((chunk: webpack.Chunk) => {
...@@ -394,7 +383,7 @@ export class FlightManifestPlugin { ...@@ -394,7 +383,7 @@ export class FlightManifestPlugin {
} }
}) })
const entryCSSFiles: any = manifest.__entry_css_files__ || {} const entryCSSFiles: { [key: string]: string[] } = manifest.cssFiles || {}
const addCSSFilesToEntry = ( const addCSSFilesToEntry = (
files: string[], files: string[],
...@@ -423,7 +412,7 @@ export class FlightManifestPlugin { ...@@ -423,7 +412,7 @@ export class FlightManifestPlugin {
}) })
} }
manifest.__entry_css_files__ = entryCSSFiles manifest.cssFiles = entryCSSFiles
}) })
const file = 'server/' + CLIENT_REFERENCE_MANIFEST const file = 'server/' + CLIENT_REFERENCE_MANIFEST
......
...@@ -482,7 +482,7 @@ export default async function exportApp( ...@@ -482,7 +482,7 @@ export default async function exportApp(
if (options.buildExport && hasAppDir) { if (options.buildExport && hasAppDir) {
// @ts-expect-error untyped // @ts-expect-error untyped
renderOpts.serverComponentManifest = require(join( renderOpts.clientReferenceManifest = require(join(
distDir, distDir,
SERVER_DIRECTORY, SERVER_DIRECTORY,
CLIENT_REFERENCE_MANIFEST + '.json' CLIENT_REFERENCE_MANIFEST + '.json'
......
/**
* filepath export module key
* "file" '*' "file"
* "file" '' "file#"
* "file" '<named>' "file#<named>"
*
* @param filepath file path to the module
* @param exports '' | '*' | '<named>'
*/
export function getClientReferenceModuleKey(
filepath: string,
exportName: string
): string {
return exportName === '*' ? filepath : filepath + '#' + exportName
}
export function isClientReference(reference: any): boolean {
return reference?.$$typeof === Symbol.for('react.client.reference')
}
...@@ -8,7 +8,7 @@ import { createDefaultMetadata } from './default-metadata' ...@@ -8,7 +8,7 @@ import { createDefaultMetadata } from './default-metadata'
import { resolveOpenGraph, resolveTwitter } from './resolvers/resolve-opengraph' import { resolveOpenGraph, resolveTwitter } from './resolvers/resolve-opengraph'
import { resolveTitle } from './resolvers/resolve-title' import { resolveTitle } from './resolvers/resolve-title'
import { resolveAsArrayOrUndefined } from './generate/utils' import { resolveAsArrayOrUndefined } from './generate/utils'
import { isClientReference } from '../../build/is-client-reference' import { isClientReference } from '../client-reference'
import { import {
getLayoutOrPageModule, getLayoutOrPageModule,
LoaderTree, LoaderTree,
......
import type { IncomingMessage, ServerResponse } from 'http' import type { IncomingMessage, ServerResponse } from 'http'
import type { NextFontManifest } from '../../build/webpack/plugins/next-font-manifest-plugin' import type { NextFontManifest } from '../../build/webpack/plugins/next-font-manifest-plugin'
import type { import {
FlightCSSManifest, ClientCSSReferenceManifest,
FlightManifest, ClientReferenceManifest,
} from '../../build/webpack/plugins/flight-manifest-plugin' } from '../../build/webpack/plugins/flight-manifest-plugin'
import type { import type {
ChildProp, ChildProp,
...@@ -58,7 +58,10 @@ import { MetadataTree } from '../../lib/metadata/metadata' ...@@ -58,7 +58,10 @@ import { MetadataTree } from '../../lib/metadata/metadata'
import { RequestAsyncStorageWrapper } from '../async-storage/request-async-storage-wrapper' import { RequestAsyncStorageWrapper } from '../async-storage/request-async-storage-wrapper'
import { StaticGenerationAsyncStorageWrapper } from '../async-storage/static-generation-async-storage-wrapper' import { StaticGenerationAsyncStorageWrapper } from '../async-storage/static-generation-async-storage-wrapper'
import { collectMetadata } from '../../lib/metadata/resolve-metadata' import { collectMetadata } from '../../lib/metadata/resolve-metadata'
import { isClientReference } from '../../build/is-client-reference' import {
getClientReferenceModuleKey,
isClientReference,
} from '../../lib/client-reference'
import { getLayoutOrPageModule, LoaderTree } from '../lib/app-dir-module' import { getLayoutOrPageModule, LoaderTree } from '../lib/app-dir-module'
import { warnOnce } from '../../shared/lib/utils/warn-once' import { warnOnce } from '../../shared/lib/utils/warn-once'
import { isNotFoundError } from '../../client/components/not-found' import { isNotFoundError } from '../../client/components/not-found'
...@@ -217,7 +220,7 @@ interface FlightResponseRef { ...@@ -217,7 +220,7 @@ interface FlightResponseRef {
function useFlightResponse( function useFlightResponse(
writable: WritableStream<Uint8Array>, writable: WritableStream<Uint8Array>,
req: ReadableStream<Uint8Array>, req: ReadableStream<Uint8Array>,
serverComponentManifest: any, clientReferenceManifest: ClientReferenceManifest,
rscChunks: Uint8Array[], rscChunks: Uint8Array[],
flightResponseRef: FlightResponseRef, flightResponseRef: FlightResponseRef,
nonce?: string nonce?: string
...@@ -232,8 +235,8 @@ function useFlightResponse( ...@@ -232,8 +235,8 @@ function useFlightResponse(
const [renderStream, forwardStream] = readableStreamTee(req) const [renderStream, forwardStream] = readableStreamTee(req)
const res = createFromReadableStream(renderStream, { const res = createFromReadableStream(renderStream, {
moduleMap: isEdgeRuntime moduleMap: isEdgeRuntime
? serverComponentManifest.__edge_ssr_module_mapping__ ? clientReferenceManifest.edgeSSRModuleMapping
: serverComponentManifest.__ssr_module_mapping__, : clientReferenceManifest.ssrModuleMapping,
}) })
flightResponseRef.current = res flightResponseRef.current = res
...@@ -293,12 +296,12 @@ function createServerComponentRenderer<Props>( ...@@ -293,12 +296,12 @@ function createServerComponentRenderer<Props>(
}, },
{ {
transformStream, transformStream,
serverComponentManifest, clientReferenceManifest,
serverContexts, serverContexts,
rscChunks, rscChunks,
}: { }: {
transformStream: TransformStream<Uint8Array, Uint8Array> transformStream: TransformStream<Uint8Array, Uint8Array>
serverComponentManifest: NonNullable<RenderOpts['serverComponentManifest']> clientReferenceManifest: NonNullable<RenderOpts['clientReferenceManifest']>
serverContexts: Array< serverContexts: Array<
[ServerContextName: string, JSONValue: Object | number | string] [ServerContextName: string, JSONValue: Object | number | string]
> >
...@@ -322,7 +325,7 @@ function createServerComponentRenderer<Props>( ...@@ -322,7 +325,7 @@ function createServerComponentRenderer<Props>(
if (!RSCStream) { if (!RSCStream) {
RSCStream = ComponentMod.renderToReadableStream( RSCStream = ComponentMod.renderToReadableStream(
<ComponentToRender {...(props as any)} />, <ComponentToRender {...(props as any)} />,
serverComponentManifest, clientReferenceManifest.clientModules,
{ {
context: serverContexts, context: serverContexts,
onError: serverComponentsErrorHandler, onError: serverComponentsErrorHandler,
...@@ -340,7 +343,7 @@ function createServerComponentRenderer<Props>( ...@@ -340,7 +343,7 @@ function createServerComponentRenderer<Props>(
const response = useFlightResponse( const response = useFlightResponse(
writable, writable,
reqStream, reqStream,
serverComponentManifest, clientReferenceManifest,
rscChunks, rscChunks,
flightResponseRef, flightResponseRef,
nonce nonce
...@@ -402,18 +405,18 @@ function getSegmentParam(segment: string): { ...@@ -402,18 +405,18 @@ function getSegmentParam(segment: string): {
* Get inline <link> tags based on server CSS manifest. Only used when rendering to HTML. * Get inline <link> tags based on server CSS manifest. Only used when rendering to HTML.
*/ */
function getCssInlinedLinkTags( function getCssInlinedLinkTags(
serverComponentManifest: FlightManifest, clientReferenceManifest: ClientReferenceManifest,
serverCSSManifest: FlightCSSManifest, serverCSSManifest: ClientCSSReferenceManifest,
filePath: string, filePath: string,
serverCSSForEntries: string[], serverCSSForEntries: string[],
injectedCSS: Set<string>, injectedCSS: Set<string>,
collectNewCSSImports?: boolean collectNewCSSImports?: boolean
): string[] { ): string[] {
const layoutOrPageCssModules = serverCSSManifest[filePath] const layoutOrPageCssModules = serverCSSManifest.cssImports[filePath]
const filePathWithoutExt = filePath.replace(/\.[^.]+$/, '') const filePathWithoutExt = filePath.replace(/\.[^.]+$/, '')
const cssFilesForEntry = new Set( const cssFilesForEntry = new Set(
serverComponentManifest.__entry_css_files__?.[filePathWithoutExt] || [] clientReferenceManifest.cssFiles?.[filePathWithoutExt] || []
) )
if (!layoutOrPageCssModules || !cssFilesForEntry.size) { if (!layoutOrPageCssModules || !cssFilesForEntry.size) {
...@@ -431,7 +434,10 @@ function getCssInlinedLinkTags( ...@@ -431,7 +434,10 @@ function getCssInlinedLinkTags(
// If the CSS is already injected by a parent layer, we don't need // If the CSS is already injected by a parent layer, we don't need
// to inject it again. // to inject it again.
if (!injectedCSS.has(mod)) { if (!injectedCSS.has(mod)) {
const modData = serverComponentManifest[mod + '#'] const modData =
clientReferenceManifest.clientModules[
getClientReferenceModuleKey(mod, '')
]
if (modData) { if (modData) {
for (const chunk of modData.chunks) { for (const chunk of modData.chunks) {
// If the current entry in the final tree-shaked bundle has that CSS // If the current entry in the final tree-shaked bundle has that CSS
...@@ -454,17 +460,17 @@ function getCssInlinedLinkTags( ...@@ -454,17 +460,17 @@ function getCssInlinedLinkTags(
} }
function getServerCSSForEntries( function getServerCSSForEntries(
serverCSSManifest: FlightCSSManifest, serverCSSManifest: ClientCSSReferenceManifest,
entries: string[] entries: string[]
) { ) {
const css = [] const css = []
for (const entry of entries) { for (const entry of entries) {
const entryName = entry.replace(/\.[^.]+$/, '') const entryName = entry.replace(/\.[^.]+$/, '')
if ( if (
serverCSSManifest.__entry_css_mods__ && serverCSSManifest.cssModules &&
serverCSSManifest.__entry_css_mods__[entryName] serverCSSManifest.cssModules[entryName]
) { ) {
css.push(...serverCSSManifest.__entry_css_mods__[entryName]) css.push(...serverCSSManifest.cssModules[entryName])
} }
} }
return css return css
...@@ -474,7 +480,7 @@ function getServerCSSForEntries( ...@@ -474,7 +480,7 @@ function getServerCSSForEntries(
* Get inline <link rel="preload" as="font"> tags based on server CSS manifest and next/font manifest. Only used when rendering to HTML. * Get inline <link rel="preload" as="font"> tags based on server CSS manifest and next/font manifest. Only used when rendering to HTML.
*/ */
function getPreloadedFontFilesInlineLinkTags( function getPreloadedFontFilesInlineLinkTags(
serverCSSManifest: FlightCSSManifest, serverCSSManifest: ClientCSSReferenceManifest,
nextFontManifest: NextFontManifest | undefined, nextFontManifest: NextFontManifest | undefined,
serverCSSForEntries: string[], serverCSSForEntries: string[],
filePath: string | undefined, filePath: string | undefined,
...@@ -483,7 +489,7 @@ function getPreloadedFontFilesInlineLinkTags( ...@@ -483,7 +489,7 @@ function getPreloadedFontFilesInlineLinkTags(
if (!nextFontManifest || !filePath) { if (!nextFontManifest || !filePath) {
return null return null
} }
const layoutOrPageCss = serverCSSManifest[filePath] const layoutOrPageCss = serverCSSManifest.cssImports[filePath]
if (!layoutOrPageCss) { if (!layoutOrPageCss) {
return null return null
...@@ -631,15 +637,16 @@ export async function renderToHTMLOrFlight( ...@@ -631,15 +637,16 @@ export async function renderToHTMLOrFlight(
const { const {
buildManifest, buildManifest,
subresourceIntegrityManifest, subresourceIntegrityManifest,
serverComponentManifest,
serverActionsManifest, serverActionsManifest,
serverCSSManifest = {},
ComponentMod, ComponentMod,
dev, dev,
nextFontManifest, nextFontManifest,
supportsDynamicHTML, supportsDynamicHTML,
} = renderOpts } = renderOpts
const clientReferenceManifest = renderOpts.clientReferenceManifest!
const serverCSSManifest = renderOpts.serverCSSManifest!
const capturedErrors: Error[] = [] const capturedErrors: Error[] = []
const allCapturedErrors: Error[] = [] const allCapturedErrors: Error[] = []
const isNextExport = !!renderOpts.nextExport const isNextExport = !!renderOpts.nextExport
...@@ -918,8 +925,8 @@ export async function renderToHTMLOrFlight( ...@@ -918,8 +925,8 @@ export async function renderToHTMLOrFlight(
injectedCSS: Set<string> injectedCSS: Set<string>
}): Promise<any> => { }): Promise<any> => {
const cssHrefs = getCssInlinedLinkTags( const cssHrefs = getCssInlinedLinkTags(
serverComponentManifest, clientReferenceManifest,
serverCSSManifest, serverCSSManifest!,
filePath, filePath,
serverCSSForEntries, serverCSSForEntries,
injectedCSS injectedCSS
...@@ -983,7 +990,7 @@ export async function renderToHTMLOrFlight( ...@@ -983,7 +990,7 @@ export async function renderToHTMLOrFlight(
const injectedCSSWithCurrentLayout = new Set(injectedCSS) const injectedCSSWithCurrentLayout = new Set(injectedCSS)
const stylesheets: string[] = layoutOrPagePath const stylesheets: string[] = layoutOrPagePath
? getCssInlinedLinkTags( ? getCssInlinedLinkTags(
serverComponentManifest, clientReferenceManifest,
serverCSSManifest!, serverCSSManifest!,
layoutOrPagePath, layoutOrPagePath,
serverCSSForEntries, serverCSSForEntries,
...@@ -1461,7 +1468,7 @@ export async function renderToHTMLOrFlight( ...@@ -1461,7 +1468,7 @@ export async function renderToHTMLOrFlight(
) )
if (layoutPath) { if (layoutPath) {
getCssInlinedLinkTags( getCssInlinedLinkTags(
serverComponentManifest, clientReferenceManifest,
serverCSSManifest!, serverCSSManifest!,
layoutPath, layoutPath,
serverCSSForEntries, serverCSSForEntries,
...@@ -1544,7 +1551,7 @@ export async function renderToHTMLOrFlight( ...@@ -1544,7 +1551,7 @@ export async function renderToHTMLOrFlight(
// which contains the subset React. // which contains the subset React.
const readable = ComponentMod.renderToReadableStream( const readable = ComponentMod.renderToReadableStream(
flightData, flightData,
serverComponentManifest, clientReferenceManifest.clientModules,
{ {
context: serverContexts, context: serverContexts,
onError: flightDataRendererErrorHandler, onError: flightDataRendererErrorHandler,
...@@ -1585,7 +1592,7 @@ export async function renderToHTMLOrFlight( ...@@ -1585,7 +1592,7 @@ export async function renderToHTMLOrFlight(
const serverComponentsRenderOpts = { const serverComponentsRenderOpts = {
transformStream: serverComponentsInlinedTransformStream, transformStream: serverComponentsInlinedTransformStream,
serverComponentManifest, clientReferenceManifest,
serverContexts, serverContexts,
rscChunks: [], rscChunks: [],
} }
......
import type { LoadComponentsReturnType } from '../load-components' import type { LoadComponentsReturnType } from '../load-components'
import type { ServerRuntime } from '../../../types' import type { ServerRuntime } from '../../../types'
import type { import type {
FlightCSSManifest, ClientCSSReferenceManifest,
FlightManifest, ClientReferenceManifest,
} from '../../build/webpack/plugins/flight-manifest-plugin' } from '../../build/webpack/plugins/flight-manifest-plugin'
import type { NextFontManifest } from '../../build/webpack/plugins/next-font-manifest-plugin' import type { NextFontManifest } from '../../build/webpack/plugins/next-font-manifest-plugin'
...@@ -114,8 +114,8 @@ export type ChildProp = { ...@@ -114,8 +114,8 @@ export type ChildProp = {
export type RenderOptsPartial = { export type RenderOptsPartial = {
err?: Error | null err?: Error | null
dev?: boolean dev?: boolean
serverComponentManifest?: FlightManifest clientReferenceManifest?: ClientReferenceManifest
serverCSSManifest?: FlightCSSManifest serverCSSManifest?: ClientCSSReferenceManifest
supportsDynamicHTML: boolean supportsDynamicHTML: boolean
runtime?: ServerRuntime runtime?: ServerRuntime
serverComponents?: boolean serverComponents?: boolean
......
...@@ -28,6 +28,7 @@ import type { PagesManifest } from '../build/webpack/plugins/pages-manifest-plug ...@@ -28,6 +28,7 @@ import type { PagesManifest } from '../build/webpack/plugins/pages-manifest-plug
import type { BaseNextRequest, BaseNextResponse } from './base-http' import type { BaseNextRequest, BaseNextResponse } from './base-http'
import type { PayloadOptions } from './send-payload' import type { PayloadOptions } from './send-payload'
import type { PrerenderManifest } from '../build' import type { PrerenderManifest } from '../build'
import type { ClientReferenceManifest } from '../build/webpack/plugins/flight-manifest-plugin'
import type { NextFontManifest } from '../build/webpack/plugins/next-font-manifest-plugin' import type { NextFontManifest } from '../build/webpack/plugins/next-font-manifest-plugin'
import { format as formatUrl, parse as parseUrl } from 'url' import { format as formatUrl, parse as parseUrl } from 'url'
...@@ -227,7 +228,7 @@ export default abstract class Server<ServerOptions extends Options = Options> { ...@@ -227,7 +228,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
crossOrigin?: string crossOrigin?: string
supportsDynamicHTML?: boolean supportsDynamicHTML?: boolean
isBot?: boolean isBot?: boolean
serverComponentManifest?: any clientReferenceManifest?: ClientReferenceManifest
serverCSSManifest?: any serverCSSManifest?: any
serverActionsManifest?: any serverActionsManifest?: any
nextFontManifest?: NextFontManifest nextFontManifest?: NextFontManifest
...@@ -241,7 +242,7 @@ export default abstract class Server<ServerOptions extends Options = Options> { ...@@ -241,7 +242,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
protected router: Router protected router: Router
protected appPathRoutes?: Record<string, string[]> protected appPathRoutes?: Record<string, string[]>
protected customRoutes: CustomRoutes protected customRoutes: CustomRoutes
protected serverComponentManifest?: any protected clientReferenceManifest?: ClientReferenceManifest
protected serverCSSManifest?: any protected serverCSSManifest?: any
protected nextFontManifest?: NextFontManifest protected nextFontManifest?: NextFontManifest
public readonly hostname?: string public readonly hostname?: string
...@@ -386,7 +387,7 @@ export default abstract class Server<ServerOptions extends Options = Options> { ...@@ -386,7 +387,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
this.hasAppDir = this.hasAppDir =
!!this.nextConfig.experimental.appDir && this.getHasAppDir(dev) !!this.nextConfig.experimental.appDir && this.getHasAppDir(dev)
const serverComponents = this.hasAppDir const serverComponents = this.hasAppDir
this.serverComponentManifest = serverComponents this.clientReferenceManifest = serverComponents
? this.getServerComponentManifest() ? this.getServerComponentManifest()
: undefined : undefined
this.serverCSSManifest = serverComponents this.serverCSSManifest = serverComponents
...@@ -1250,7 +1251,7 @@ export default abstract class Server<ServerOptions extends Options = Options> { ...@@ -1250,7 +1251,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
// Don't delete headers[RSC] yet, it still needs to be used in renderToHTML later // Don't delete headers[RSC] yet, it still needs to be used in renderToHTML later
const isFlightRequest = Boolean( const isFlightRequest = Boolean(
this.serverComponentManifest && req.headers[RSC.toLowerCase()] this.clientReferenceManifest && req.headers[RSC.toLowerCase()]
) )
// For pages we need to ensure the correct Vary header is set too, to avoid // For pages we need to ensure the correct Vary header is set too, to avoid
......
...@@ -1661,7 +1661,7 @@ export default class DevServer extends Server { ...@@ -1661,7 +1661,7 @@ export default class DevServer extends Server {
// When the new page is compiled, we need to reload the server component // When the new page is compiled, we need to reload the server component
// manifest. // manifest.
if (!!this.appDir) { if (!!this.appDir) {
this.serverComponentManifest = super.getServerComponentManifest() this.clientReferenceManifest = super.getServerComponentManifest()
this.serverCSSManifest = super.getServerCSSManifest() this.serverCSSManifest = super.getServerCSSManifest()
} }
this.nextFontManifest = super.getNextFontManifest() this.nextFontManifest = super.getNextFontManifest()
......
...@@ -3,6 +3,7 @@ import type { ...@@ -3,6 +3,7 @@ import type {
DocumentType, DocumentType,
NextComponentType, NextComponentType,
} from '../shared/lib/utils' } from '../shared/lib/utils'
import type { ClientReferenceManifest } from '../build/webpack/plugins/flight-manifest-plugin'
import type { import type {
PageConfig, PageConfig,
GetStaticPaths, GetStaticPaths,
...@@ -35,7 +36,7 @@ export type LoadComponentsReturnType = { ...@@ -35,7 +36,7 @@ export type LoadComponentsReturnType = {
buildManifest: BuildManifest buildManifest: BuildManifest
subresourceIntegrityManifest?: Record<string, string> subresourceIntegrityManifest?: Record<string, string>
reactLoadableManifest: ReactLoadableManifest reactLoadableManifest: ReactLoadableManifest
serverComponentManifest?: any clientReferenceManifest?: ClientReferenceManifest
serverActionsManifest?: any serverActionsManifest?: any
Document: DocumentType Document: DocumentType
App: AppType App: AppType
...@@ -104,16 +105,16 @@ async function loadComponentsImpl({ ...@@ -104,16 +105,16 @@ async function loadComponentsImpl({
const [ const [
buildManifest, buildManifest,
reactLoadableManifest, reactLoadableManifest,
serverComponentManifest, clientReferenceManifest,
serverActionsManifest, serverActionsManifest,
] = await Promise.all([ ] = await Promise.all([
loadManifest<BuildManifest>(join(distDir, BUILD_MANIFEST)), loadManifest<BuildManifest>(join(distDir, BUILD_MANIFEST)),
loadManifest<ReactLoadableManifest>(join(distDir, REACT_LOADABLE_MANIFEST)), loadManifest<ReactLoadableManifest>(join(distDir, REACT_LOADABLE_MANIFEST)),
hasServerComponents hasServerComponents
? loadManifest( ? loadManifest<ClientReferenceManifest>(
join(distDir, 'server', CLIENT_REFERENCE_MANIFEST + '.json') join(distDir, 'server', CLIENT_REFERENCE_MANIFEST + '.json')
) )
: null, : undefined,
hasServerComponents hasServerComponents
? loadManifest( ? loadManifest(
join(distDir, 'server', SERVER_REFERENCE_MANIFEST + '.json') join(distDir, 'server', SERVER_REFERENCE_MANIFEST + '.json')
...@@ -138,7 +139,7 @@ async function loadComponentsImpl({ ...@@ -138,7 +139,7 @@ async function loadComponentsImpl({
getServerSideProps, getServerSideProps,
getStaticProps, getStaticProps,
getStaticPaths, getStaticPaths,
serverComponentManifest, clientReferenceManifest,
serverActionsManifest, serverActionsManifest,
isAppPath, isAppPath,
pathname, pathname,
......
...@@ -852,9 +852,9 @@ export default class NextNodeServer extends BaseServer { ...@@ -852,9 +852,9 @@ export default class NextNodeServer extends BaseServer {
renderOpts: RenderOpts renderOpts: RenderOpts
): Promise<RenderResult> { ): Promise<RenderResult> {
// Due to the way we pass data by mutating `renderOpts`, we can't extend the // Due to the way we pass data by mutating `renderOpts`, we can't extend the
// object here but only updating its `serverComponentManifest` field. // object here but only updating its `clientReferenceManifest` field.
// https://github.com/vercel/next.js/blob/df7cbd904c3bd85f399d1ce90680c0ecf92d2752/packages/next/server/render.tsx#L947-L952 // https://github.com/vercel/next.js/blob/df7cbd904c3bd85f399d1ce90680c0ecf92d2752/packages/next/server/render.tsx#L947-L952
renderOpts.serverComponentManifest = this.serverComponentManifest renderOpts.clientReferenceManifest = this.clientReferenceManifest
renderOpts.serverCSSManifest = this.serverCSSManifest renderOpts.serverCSSManifest = this.serverCSSManifest
renderOpts.nextFontManifest = this.nextFontManifest renderOpts.nextFontManifest = this.nextFontManifest
......
...@@ -26,6 +26,7 @@ import type { ...@@ -26,6 +26,7 @@ import type {
} from 'next/types' } from 'next/types'
import type { UnwrapPromise } from '../lib/coalesced-function' import type { UnwrapPromise } from '../lib/coalesced-function'
import type { ReactReadableStream } from './node-web-streams-helper' import type { ReactReadableStream } from './node-web-streams-helper'
import type { ClientReferenceManifest } from '../build/webpack/plugins/flight-manifest-plugin'
import type { NextFontManifest } from '../build/webpack/plugins/next-font-manifest-plugin' import type { NextFontManifest } from '../build/webpack/plugins/next-font-manifest-plugin'
import React from 'react' import React from 'react'
...@@ -246,7 +247,7 @@ export type RenderOptsPartial = { ...@@ -246,7 +247,7 @@ export type RenderOptsPartial = {
devOnlyCacheBusterQueryString?: string devOnlyCacheBusterQueryString?: string
resolvedUrl?: string resolvedUrl?: string
resolvedAsPath?: string resolvedAsPath?: string
serverComponentManifest?: any clientReferenceManifest?: ClientReferenceManifest
serverCSSManifest?: any serverCSSManifest?: any
nextFontManifest?: NextFontManifest nextFontManifest?: NextFontManifest
distDir?: string distDir?: string
......
...@@ -170,7 +170,7 @@ export default class NextWebServer extends BaseServer<WebServerOptions> { ...@@ -170,7 +170,7 @@ export default class NextWebServer extends BaseServer<WebServerOptions> {
} }
protected getServerComponentManifest() { protected getServerComponentManifest() {
return this.serverOptions.webServerConfig.extendRenderOpts return this.serverOptions.webServerConfig.extendRenderOpts
.serverComponentManifest .clientReferenceManifest
} }
protected getServerCSSManifest() { protected getServerCSSManifest() {
return this.serverOptions.webServerConfig.extendRenderOpts.serverCSSManifest return this.serverOptions.webServerConfig.extendRenderOpts.serverCSSManifest
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment