Skip to content

Commit 122f1b3

Browse files
nameofnameScriptedAlchemyRon
authored
fix: remove chunks from installedChunks on fail to enable retries (#3686)
Co-authored-by: Zack Jackson <[email protected]> Co-authored-by: Ron <[email protected]>
1 parent 772d74b commit 122f1b3

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

.changeset/green-crews-melt.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/node': patch
3+
---
4+
5+
fix: remove chunks from installedChunks on fail to enable retries

packages/node/src/runtimePlugin.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,15 @@ export const installChunk = (
235235
}
236236
};
237237

238+
// Hoisted utility function to remove a chunk on fail
239+
export const deleteChunk = (
240+
chunkId: string,
241+
installedChunks: { [key: string]: any },
242+
): boolean => {
243+
delete installedChunks[chunkId];
244+
return true;
245+
};
246+
238247
// Hoisted function to set up webpack script loader
239248
export const setupScriptLoader = (): void => {
240249
__webpack_require__.l = (
@@ -297,7 +306,8 @@ export const setupChunkHandler = (
297306
chunkId,
298307
__webpack_require__.federation.rootOutputDir || '',
299308
(err, chunk) => {
300-
if (err) return reject(err);
309+
if (err)
310+
return deleteChunk(chunkId, installedChunks) && reject(err);
301311
if (chunk) installChunk(chunk, installedChunks);
302312
resolve(chunk);
303313
},
@@ -312,7 +322,8 @@ export const setupChunkHandler = (
312322
chunkName,
313323
__webpack_require__.federation.initOptions.name,
314324
(err, chunk) => {
315-
if (err) return reject(err);
325+
if (err)
326+
return deleteChunk(chunkId, installedChunks) && reject(err);
316327
if (chunk) installChunk(chunk, installedChunks);
317328
resolve(chunk);
318329
},

0 commit comments

Comments
 (0)