Skip to content

Commit

Permalink
fix(enhanced): async boundary on dependOn named chunks (#1960)
Browse files Browse the repository at this point in the history
Co-authored-by: ScriptedAlchemy <[email protected]>
  • Loading branch information
ScriptedAlchemy and ScriptedAlchemy authored Jan 16, 2024
1 parent a500f61 commit 51b18e0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/metal-walls-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@module-federation/enhanced': patch
---

Fix bug in AyncBoundaryPlugin when chunkID is not set to named and dependOn exists
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,4 @@ apps/**/dist
# test cases
!packages/enhanced/test/configCases/**/**/node_modules
packages/enhanced/test/js
.ignored
28 changes: 21 additions & 7 deletions packages/enhanced/src/lib/container/AsyncBoundaryPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,20 @@ class AsyncEntryStartupPlugin {
});
}

getChunkByName(
compilation: Compilation,
dependOn: string[],
): (string | number | undefined)[] {
const byname = [];
for (const name of dependOn) {
const chunk = compilation.namedChunks.get(name);
if (chunk) {
byname.push(chunk.id || chunk.name);
}
}
return byname;
}

private _handleRenderStartup(compiler: Compiler, compilation: Compilation) {
compiler.webpack.javascript.JavascriptModulesPlugin.getCompilationHooks(
compilation,
Expand Down Expand Up @@ -118,9 +132,9 @@ class AsyncEntryStartupPlugin {
const initialChunks = Array.from(
upperContext.chunk.getAllInitialChunks(),
).map((chunk: Chunk) => chunk.id);
const chunksToRef = entryOptions?.dependOn
? [...entryOptions.dependOn, ...initialChunks]
: [...initialChunks];
const dependOn = entryOptions?.dependOn || [];
const dependOnIDs = this.getChunkByName(compilation, dependOn);
const chunksToRef = [...dependOnIDs, ...initialChunks];

remotes = this._getRemotes(
compiler.webpack.RuntimeGlobals,
Expand Down Expand Up @@ -181,7 +195,7 @@ class AsyncEntryStartupPlugin {
runtimeGlobals: typeof RuntimeGlobals,
requirements: ReadonlySet<string>,
hasRemoteModules: boolean,
chunksToRef: (Chunk['id'] | null)[],
chunksToRef: (Chunk['id'] | null | undefined)[],
remotes: string,
): string {
if (
Expand All @@ -202,7 +216,7 @@ class AsyncEntryStartupPlugin {
];

for (const chunkId of chunksToRef) {
if (chunkId !== null) {
if (chunkId !== null && chunkId !== undefined) {
remotesParts.push(
` __webpack_require__.f.remotes(${JSON.stringify(
chunkId,
Expand All @@ -219,7 +233,7 @@ class AsyncEntryStartupPlugin {
runtimeGlobals: typeof RuntimeGlobals,
requirements: ReadonlySet<string>,
consumeShares: boolean,
chunksToRef: (Chunk['id'] | null)[],
chunksToRef: (Chunk['id'] | null | undefined)[],
shared: string,
): string {
if (
Expand All @@ -240,7 +254,7 @@ class AsyncEntryStartupPlugin {
];

for (const chunkId of chunksToRef) {
if (chunkId !== null) {
if (chunkId !== null && chunkId !== undefined) {
sharedParts.push(
` __webpack_require__.f.consumes(${JSON.stringify(
chunkId,
Expand Down

0 comments on commit 51b18e0

Please sign in to comment.