Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor the client entry plugin #52798

Merged
merged 2 commits into from
Jul 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,13 @@ export class FlightClientEntryPlugin {
entryModule
)) {
// 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 { clientComponentImports, actionImports, cssImports } =
this.collectComponentInfoFromServerEntryDependency({
entryRequest,
compilation,
dependency: entryDependency,
resolvedModule: connection.resolvedModule,
})

actionImports.forEach(([dep, names]) =>
Expand Down Expand Up @@ -493,14 +492,12 @@ export class FlightClientEntryPlugin {

const collectActions = ({
entryRequest,
dependency,
resolvedModule,
}: {
entryRequest: string
dependency: any /* Dependency */
resolvedModule: any
}) => {
const collectActionsInDep = (dependencyToFilter: any): void => {
const mod: webpack.NormalModule =
compilation.moduleGraph.getResolvedModule(dependencyToFilter)
const collectActionsInDep = (mod: webpack.NormalModule): void => {
if (!mod) return

// We have to always use the resolved request here to make sure the
Expand All @@ -520,14 +517,14 @@ export class FlightClientEntryPlugin {
compilation.moduleGraph
.getOutgoingConnections(mod)
.forEach((connection: any) => {
collectActionsInDep(connection.dependency)
collectActionsInDep(connection.resolvedModule)
})
}

// Don't traverse the module graph anymore once hitting the action layer.
if (!entryRequest.includes('next-flight-action-entry-loader')) {
// Traverse the module graph to find all client components.
collectActionsInDep(dependency)
collectActionsInDep(resolvedModule)
}
}

Expand All @@ -547,7 +544,7 @@ export class FlightClientEntryPlugin {

collectActions({
entryRequest: request,
dependency,
resolvedModule: connection.resolvedModule,
})
}
}
Expand All @@ -558,11 +555,11 @@ export class FlightClientEntryPlugin {
collectComponentInfoFromServerEntryDependency({
entryRequest,
compilation,
dependency,
resolvedModule,
}: {
entryRequest: string
compilation: any
dependency: any /* Dependency */
resolvedModule: any /* Dependency */
}): {
cssImports: CssImports
clientComponentImports: ClientComponentImports
Expand All @@ -576,9 +573,7 @@ export class FlightClientEntryPlugin {
const actionImports: [string, string[]][] = []
const CSSImports = new Set<string>()

const filterClientComponents = (dependencyToFilter: any): void => {
const mod: webpack.NormalModule =
compilation.moduleGraph.getResolvedModule(dependencyToFilter)
const filterClientComponents = (mod: webpack.NormalModule): void => {
if (!mod) return

const isCSS = isCSSMod(mod)
Expand Down Expand Up @@ -622,12 +617,12 @@ export class FlightClientEntryPlugin {
compilation.moduleGraph
.getOutgoingConnections(mod)
.forEach((connection: any) => {
filterClientComponents(connection.dependency)
filterClientComponents(connection.resolvedModule)
})
}

// Traverse the module graph to find all client components.
filterClientComponents(dependency)
filterClientComponents(resolvedModule)

return {
clientComponentImports,
Expand Down