Unverified Commit 56d85f25 authored by Shu Ding's avatar Shu Ding Committed by GitHub

Refactor the client entry plugin (#52798)

Changing `compilation.moduleGraph.getResolvedModule(dependencyToFilter)`
to `connection.resolvedModule` to make the code simpler.
parent 33385aad
...@@ -265,14 +265,13 @@ export class FlightClientEntryPlugin { ...@@ -265,14 +265,13 @@ export class FlightClientEntryPlugin {
entryModule entryModule
)) { )) {
// Entry can be any user defined entry files such as layout, page, error, loading, etc. // Entry can be any user defined entry files such as layout, page, error, loading, etc.
const entryDependency = connection.dependency
const entryRequest = connection.dependency.request const entryRequest = connection.dependency.request
const { clientComponentImports, actionImports, cssImports } = const { clientComponentImports, actionImports, cssImports } =
this.collectComponentInfoFromServerEntryDependency({ this.collectComponentInfoFromServerEntryDependency({
entryRequest, entryRequest,
compilation, compilation,
dependency: entryDependency, resolvedModule: connection.resolvedModule,
}) })
actionImports.forEach(([dep, names]) => actionImports.forEach(([dep, names]) =>
...@@ -493,14 +492,12 @@ export class FlightClientEntryPlugin { ...@@ -493,14 +492,12 @@ export class FlightClientEntryPlugin {
const collectActions = ({ const collectActions = ({
entryRequest, entryRequest,
dependency, resolvedModule,
}: { }: {
entryRequest: string entryRequest: string
dependency: any /* Dependency */ resolvedModule: any
}) => { }) => {
const collectActionsInDep = (dependencyToFilter: any): void => { const collectActionsInDep = (mod: webpack.NormalModule): void => {
const mod: webpack.NormalModule =
compilation.moduleGraph.getResolvedModule(dependencyToFilter)
if (!mod) return if (!mod) return
// We have to always use the resolved request here to make sure the // We have to always use the resolved request here to make sure the
...@@ -520,14 +517,14 @@ export class FlightClientEntryPlugin { ...@@ -520,14 +517,14 @@ export class FlightClientEntryPlugin {
compilation.moduleGraph compilation.moduleGraph
.getOutgoingConnections(mod) .getOutgoingConnections(mod)
.forEach((connection: any) => { .forEach((connection: any) => {
collectActionsInDep(connection.dependency) collectActionsInDep(connection.resolvedModule)
}) })
} }
// Don't traverse the module graph anymore once hitting the action layer. // Don't traverse the module graph anymore once hitting the action layer.
if (!entryRequest.includes('next-flight-action-entry-loader')) { if (!entryRequest.includes('next-flight-action-entry-loader')) {
// Traverse the module graph to find all client components. // Traverse the module graph to find all client components.
collectActionsInDep(dependency) collectActionsInDep(resolvedModule)
} }
} }
...@@ -547,7 +544,7 @@ export class FlightClientEntryPlugin { ...@@ -547,7 +544,7 @@ export class FlightClientEntryPlugin {
collectActions({ collectActions({
entryRequest: request, entryRequest: request,
dependency, resolvedModule: connection.resolvedModule,
}) })
} }
} }
...@@ -558,11 +555,11 @@ export class FlightClientEntryPlugin { ...@@ -558,11 +555,11 @@ export class FlightClientEntryPlugin {
collectComponentInfoFromServerEntryDependency({ collectComponentInfoFromServerEntryDependency({
entryRequest, entryRequest,
compilation, compilation,
dependency, resolvedModule,
}: { }: {
entryRequest: string entryRequest: string
compilation: any compilation: any
dependency: any /* Dependency */ resolvedModule: any /* Dependency */
}): { }): {
cssImports: CssImports cssImports: CssImports
clientComponentImports: ClientComponentImports clientComponentImports: ClientComponentImports
...@@ -576,9 +573,7 @@ export class FlightClientEntryPlugin { ...@@ -576,9 +573,7 @@ export class FlightClientEntryPlugin {
const actionImports: [string, string[]][] = [] const actionImports: [string, string[]][] = []
const CSSImports = new Set<string>() const CSSImports = new Set<string>()
const filterClientComponents = (dependencyToFilter: any): void => { const filterClientComponents = (mod: webpack.NormalModule): void => {
const mod: webpack.NormalModule =
compilation.moduleGraph.getResolvedModule(dependencyToFilter)
if (!mod) return if (!mod) return
const isCSS = isCSSMod(mod) const isCSS = isCSSMod(mod)
...@@ -627,12 +622,12 @@ export class FlightClientEntryPlugin { ...@@ -627,12 +622,12 @@ export class FlightClientEntryPlugin {
compilation.moduleGraph compilation.moduleGraph
.getOutgoingConnections(mod) .getOutgoingConnections(mod)
.forEach((connection: any) => { .forEach((connection: any) => {
filterClientComponents(connection.dependency) filterClientComponents(connection.resolvedModule)
}) })
} }
// Traverse the module graph to find all client components. // Traverse the module graph to find all client components.
filterClientComponents(dependency) filterClientComponents(resolvedModule)
return { return {
clientComponentImports, clientComponentImports,
......
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