Skip to content

Commit

Permalink
feat(runtime): allow onload hook to return wrapped module (#1987)
Browse files Browse the repository at this point in the history
  • Loading branch information
ScriptedAlchemy authored Jan 19, 2024
1 parent 7659a35 commit 2d774d1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/fast-sheep-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@module-federation/runtime': patch
---

onLoad hook will allow you to return a custom module factory or proxy
6 changes: 5 additions & 1 deletion packages/runtime/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ export class FederationHost {
const { pkgNameOrAlias, remote, expose, id: idRes } = remoteMatchInfo;
const moduleOrFactory = (await module.get(expose, options)) as T;

await this.hooks.lifecycle.onLoad.emit({
const moduleWrapper = await this.hooks.lifecycle.onLoad.emit({
id: idRes,
pkgNameOrAlias,
expose,
Expand All @@ -583,6 +583,10 @@ export class FederationHost {
origin: this,
});

if (typeof moduleWrapper === 'function') {
return moduleWrapper as T;
}

return moduleOrFactory;
} catch (error) {
const { from = 'runtime' } = options || { from: 'runtime' };
Expand Down

0 comments on commit 2d774d1

Please sign in to comment.