Skip to content

Commit 2708f0c

Browse files
committed
fix: initializeSharing before load remote while shareStrategy is version first
1 parent 96efa7c commit 2708f0c

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@module-federation/webpack-bundler-runtime': patch
3+
'@module-federation/runtime': patch
4+
---
5+
6+
fix: initializeSharing before load remote while shareStrategy is version first

packages/runtime/src/core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ export class FederationHost {
215215
// eslint-disable-next-line @typescript-eslint/member-ordering
216216
async loadRemote<T>(
217217
id: string,
218-
options?: { loadFactory?: boolean; from: CallFrom },
218+
options?: { loadFactory?: boolean; from: CallFrom; shareScope?: string },
219219
): Promise<T | null> {
220220
return this.remoteHandler.loadRemote(id, options);
221221
}

packages/runtime/src/remote/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,18 @@ export class RemoteHandler {
193193
// eslint-disable-next-line @typescript-eslint/member-ordering
194194
async loadRemote<T>(
195195
id: string,
196-
options?: { loadFactory?: boolean; from: CallFrom },
196+
options?: { loadFactory?: boolean; from: CallFrom; shareScope?: string },
197197
): Promise<T | null> {
198198
const { host } = this;
199199
try {
200-
const { loadFactory = true } = options || { loadFactory: true };
200+
const { loadFactory = true, shareScope } = options || {
201+
loadFactory: true,
202+
};
203+
if (this.host.options.shareStrategy === 'version-first') {
204+
await Promise.all(
205+
this.host.sharedHandler.initializeSharing(shareScope),
206+
);
207+
}
201208
// 1. Validate the parameters of the retrieved module. There are two module request methods: pkgName + expose and alias + expose.
202209
// 2. Request the snapshot information of the current host and globally store the obtained snapshot information. The retrieved module information is partially offline and partially online. The online module information will retrieve the modules used online.
203210
// 3. Retrieve the detailed information of the current module from global (remoteEntry address, expose resource address)

packages/webpack-bundler-runtime/src/remotes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export function remotes(options: RemotesOptions) {
107107
const remoteModuleName = remoteName + data[1].slice(1);
108108
return webpackRequire.federation.instance!.loadRemote(
109109
remoteModuleName,
110-
{ loadFactory: false, from: 'build' },
110+
{ loadFactory: false, from: 'build', shareScope: data[0] },
111111
);
112112
} catch (error) {
113113
onError(error as Error);

0 commit comments

Comments
 (0)