Skip to content

Commit c2b1efa

Browse files
authored
fix: call initializeSharing before load remote while shareStrategy is version first (#3212)
1 parent 168ce96 commit c2b1efa

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
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/remote/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,9 @@ export class RemoteHandler {
197197
): Promise<T | null> {
198198
const { host } = this;
199199
try {
200-
const { loadFactory = true } = options || { loadFactory: true };
200+
const { loadFactory = true } = options || {
201+
loadFactory: true,
202+
};
201203
// 1. Validate the parameters of the retrieved module. There are two module request methods: pkgName + expose and alias + expose.
202204
// 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.
203205
// 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: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,22 @@ export function remotes(options: RemotesOptions) {
105105
);
106106

107107
const remoteModuleName = remoteName + data[1].slice(1);
108-
return webpackRequire.federation.instance!.loadRemote(
109-
remoteModuleName,
110-
{ loadFactory: false, from: 'build' },
111-
);
108+
const instance = webpackRequire.federation.instance!;
109+
const loadRemote = () =>
110+
webpackRequire.federation.instance!.loadRemote(remoteModuleName, {
111+
loadFactory: false,
112+
from: 'build',
113+
});
114+
115+
if (instance.options.shareStrategy === 'version-first') {
116+
return Promise.all(
117+
instance.sharedHandler.initializeSharing(data[0]),
118+
).then(() => {
119+
return loadRemote();
120+
});
121+
}
122+
123+
return loadRemote();
112124
} catch (error) {
113125
onError(error as Error);
114126
}

0 commit comments

Comments
 (0)