Unverified Commit 7579b418 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Remove async module detection from client flight manifest (#68584)

### What

Remove the async client modules collection from shared plugin state,
which was used for flight client manifest.


### Why

This was the legacy logic when React RSC renderer requires the `async`
property in the flight manifest, but then React dropped that change and
all the async modules are handled on the framework side, React won't do
any extra await for the modules which are marked as `async: true` in the
manifest.

The new async module logic is handled in [this
PR](https://github.com/vercel/next.js/pull/66990) now, most critically
in [this
line](https://github.com/vercel/next.js/pull/66990/files#diff-20be1066bb3785bdd9f255179957039e7ce035324bc7753aefe89ffc6bb6f1edR115).
Hence we removed that state for flight manifest.

cc @unstubbable
parent fc894024
...@@ -40,7 +40,6 @@ import { ...@@ -40,7 +40,6 @@ import {
import { normalizePathSep } from '../../../shared/lib/page-path/normalize-path-sep' import { normalizePathSep } from '../../../shared/lib/page-path/normalize-path-sep'
import { getProxiedPluginState } from '../../build-context' import { getProxiedPluginState } from '../../build-context'
import { PAGE_TYPES } from '../../../lib/page-types' import { PAGE_TYPES } from '../../../lib/page-types'
import { isWebpackServerOnlyLayer } from '../../utils'
import { getModuleBuildInfo } from '../loaders/get-module-build-info' import { getModuleBuildInfo } from '../loaders/get-module-build-info'
import { getAssumedSourceType } from '../loaders/next-flight-loader' import { getAssumedSourceType } from '../loaders/next-flight-loader'
...@@ -96,12 +95,6 @@ const pluginState = getProxiedPluginState({ ...@@ -96,12 +95,6 @@ const pluginState = getProxiedPluginState({
serverModuleIds: {} as Record<string, string | number>, serverModuleIds: {} as Record<string, string | number>,
edgeServerModuleIds: {} as Record<string, string | number>, edgeServerModuleIds: {} as Record<string, string | number>,
// Collect modules from server/edge compiler in client layer,
// and detect if it's been used, and mark it as `async: true` for react.
// So that react could unwrap the async module from promise and render module itself.
// Use an object to simulate Set lookup
ASYNC_CLIENT_MODULES: {} as Record<string, boolean>,
injectedClientEntries: {} as Record<string, string>, injectedClientEntries: {} as Record<string, string>,
}) })
...@@ -240,14 +233,6 @@ export class FlightClientEntryPlugin { ...@@ -240,14 +233,6 @@ export class FlightClientEntryPlugin {
} }
traverseModules(compilation, (mod, _chunk, _chunkGroup, modId) => { traverseModules(compilation, (mod, _chunk, _chunkGroup, modId) => {
if (mod && mod.resource && !isWebpackServerOnlyLayer(mod.layer)) {
if (compilation.moduleGraph.isAsync(mod)) {
// The module must has resolved resource path so it's not a new entry created with loader.
// Checking the module layer to make sure it's from client layers (SSR or browser, not RSC).
pluginState.ASYNC_CLIENT_MODULES[mod.resource] = true
}
}
if (modId) recordModule(modId, mod) if (modId) recordModule(modId, mod)
}) })
}) })
......
...@@ -43,8 +43,6 @@ export type ManifestChunks = Array<string> ...@@ -43,8 +43,6 @@ export type ManifestChunks = Array<string>
const pluginState = getProxiedPluginState({ const pluginState = getProxiedPluginState({
serverModuleIds: {} as Record<string, string | number>, serverModuleIds: {} as Record<string, string | number>,
edgeServerModuleIds: {} as Record<string, string | number>, edgeServerModuleIds: {} as Record<string, string | number>,
// Use an object to simulate Set lookup
ASYNC_CLIENT_MODULES: {} as Record<string, boolean>,
}) })
export interface ManifestNode { export interface ManifestNode {
...@@ -304,8 +302,6 @@ export class ClientReferenceManifestPlugin { ...@@ -304,8 +302,6 @@ export class ClientReferenceManifestPlugin {
if (!ssrNamedModuleId.startsWith('.')) if (!ssrNamedModuleId.startsWith('.'))
ssrNamedModuleId = `./${ssrNamedModuleId.replace(/\\/g, '/')}` ssrNamedModuleId = `./${ssrNamedModuleId.replace(/\\/g, '/')}`
const isAsyncModule = !!pluginState.ASYNC_CLIENT_MODULES[mod.resource]
// The client compiler will always use the CJS Next.js build, so here we // The client compiler will always use the CJS Next.js build, so here we
// also add the mapping for the ESM build (Edge runtime) to consume. // also add the mapping for the ESM build (Edge runtime) to consume.
const esmResource = /[\\/]next[\\/]dist[\\/]/.test(resource) const esmResource = /[\\/]next[\\/]dist[\\/]/.test(resource)
...@@ -333,7 +329,7 @@ export class ClientReferenceManifestPlugin { ...@@ -333,7 +329,7 @@ export class ClientReferenceManifestPlugin {
id: modId, id: modId,
name: '*', name: '*',
chunks: requiredChunks, chunks: requiredChunks,
async: isAsyncModule, async: false,
} }
if (esmResource) { if (esmResource) {
const edgeExportName = esmResource const edgeExportName = esmResource
...@@ -501,7 +497,5 @@ export class ClientReferenceManifestPlugin { ...@@ -501,7 +497,5 @@ export class ClientReferenceManifestPlugin {
)}]=${json}` )}]=${json}`
) as unknown as webpack.sources.RawSource ) as unknown as webpack.sources.RawSource
} }
pluginState.ASYNC_CLIENT_MODULES = {}
} }
} }
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