Skip to content

Commit fac6ecf

Browse files
authored
fix(runtime): catch init remote error in errorLoadRemote hook (#3019)
1 parent 15f9de1 commit fac6ecf

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/runtime': patch
3+
---
4+
5+
fix(runtime): catch init remote error in errorLoadRemote hook

packages/runtime/src/remote/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export class RemoteHandler {
102102
error: unknown;
103103
options?: any;
104104
from: CallFrom;
105-
lifecycle: 'onLoad' | 'beforeRequest';
105+
lifecycle: 'onLoad' | 'beforeRequest' | 'beforeLoadShare';
106106
origin: FederationHost;
107107
},
108108
],

packages/runtime/src/shared/index.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,21 @@ export class SharedHandler {
305305
id: key,
306306
});
307307
if (module.getEntry) {
308-
const entry = await module.getEntry();
308+
let remoteEntryExports: RemoteEntryExports;
309+
try {
310+
remoteEntryExports = await module.getEntry();
311+
} catch (error) {
312+
remoteEntryExports =
313+
(await host.remoteHandler.hooks.lifecycle.errorLoadRemote.emit({
314+
id: key,
315+
error,
316+
from: 'runtime',
317+
lifecycle: 'beforeLoadShare',
318+
origin: host,
319+
})) as RemoteEntryExports;
320+
}
309321
if (!module.inited) {
310-
await initFn(entry);
322+
await initFn(remoteEntryExports);
311323
module.inited = true;
312324
}
313325
}

0 commit comments

Comments
 (0)