Unverified Commit 41c9fe4f authored by Shu Ding's avatar Shu Ding Committed by GitHub

Refactor unused import and object in Flight plugin (#69266)

Only the `modules` field of `loaderOptions` is used.
parent bc5bba89
import type { import type {
CssImports, CssImports,
ClientComponentImports, ClientComponentImports,
FlightClientEntryModuleItem,
} from '../loaders/next-flight-client-entry-loader' } from '../loaders/next-flight-client-entry-loader'
import { webpack } from 'next/dist/compiled/webpack/webpack' import { webpack } from 'next/dist/compiled/webpack/webpack'
...@@ -841,38 +840,32 @@ export class FlightClientEntryPlugin { ...@@ -841,38 +840,32 @@ export class FlightClientEntryPlugin {
] { ] {
let shouldInvalidate = false let shouldInvalidate = false
const loaderOptions: { const modules = Object.keys(clientImports)
modules: FlightClientEntryModuleItem[] .sort((a, b) => (regexCSS.test(b) ? 1 : a.localeCompare(b)))
server: boolean .map((clientImportPath) => ({
} = { request: clientImportPath,
modules: Object.keys(clientImports) ids: [...clientImports[clientImportPath]],
.sort((a, b) => (regexCSS.test(b) ? 1 : a.localeCompare(b))) }))
.map((clientImportPath) => ({
request: clientImportPath,
ids: [...clientImports[clientImportPath]],
})),
server: false,
}
// For the client entry, we always use the CJS build of Next.js. If the // For the client entry, we always use the CJS build of Next.js. If the
// server is using the ESM build (when using the Edge runtime), we need to // server is using the ESM build (when using the Edge runtime), we need to
// replace them. // replace them.
const clientBrowserLoader = `next-flight-client-entry-loader?${stringify({ const clientBrowserLoader = `next-flight-client-entry-loader?${stringify({
modules: (this.isEdgeServer modules: (this.isEdgeServer
? loaderOptions.modules.map(({ request, ids }) => ({ ? modules.map(({ request, ids }) => ({
request: request.replace( request: request.replace(
/[\\/]next[\\/]dist[\\/]esm[\\/]/, /[\\/]next[\\/]dist[\\/]esm[\\/]/,
'/next/dist/'.replace(/\//g, path.sep) '/next/dist/'.replace(/\//g, path.sep)
), ),
ids, ids,
})) }))
: loaderOptions.modules : modules
).map((x) => JSON.stringify(x)), ).map((x) => JSON.stringify(x)),
server: false, server: false,
})}!` })}!`
const clientSSRLoader = `next-flight-client-entry-loader?${stringify({ const clientSSRLoader = `next-flight-client-entry-loader?${stringify({
modules: loaderOptions.modules.map((x) => JSON.stringify(x)), modules: modules.map((x) => JSON.stringify(x)),
server: true, server: true,
})}!` })}!`
......
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