Skip to content

Commit 2d774d1

Browse files
feat(runtime): allow onload hook to return wrapped module (#1987)
1 parent 7659a35 commit 2d774d1

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

.changeset/fast-sheep-melt.md

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+
onLoad hook will allow you to return a custom module factory or proxy

packages/runtime/src/core.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ export class FederationHost {
571571
const { pkgNameOrAlias, remote, expose, id: idRes } = remoteMatchInfo;
572572
const moduleOrFactory = (await module.get(expose, options)) as T;
573573

574-
await this.hooks.lifecycle.onLoad.emit({
574+
const moduleWrapper = await this.hooks.lifecycle.onLoad.emit({
575575
id: idRes,
576576
pkgNameOrAlias,
577577
expose,
@@ -583,6 +583,10 @@ export class FederationHost {
583583
origin: this,
584584
});
585585

586+
if (typeof moduleWrapper === 'function') {
587+
return moduleWrapper as T;
588+
}
589+
586590
return moduleOrFactory;
587591
} catch (error) {
588592
const { from = 'runtime' } = options || { from: 'runtime' };

0 commit comments

Comments
 (0)