Skip to content

Commit dade815

Browse files
authored
fix: global shared modules into wrapper (#553)
refs #543
1 parent 76e847a commit dade815

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

packages/lib/src/prod/remote-production.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export function prodRemotePlugin(
4949
})
5050
}
5151

52+
const shareScope = options.shareScope || 'default'
5253
return {
5354
name: 'originjs:remote-production',
5455
virtualFile: options.remotes
@@ -73,11 +74,21 @@ export function prodRemotePlugin(
7374
return module
7475
})
7576
}
77+
78+
function merge(obj1, obj2) {
79+
const mergedObj = Object.assign(obj1, obj2);
80+
for (const key of Object.keys(mergedObj)) {
81+
if (typeof mergedObj[key] === 'object' && typeof obj2[key] === 'object') {
82+
mergedObj[key] = merge(mergedObj[key], obj2[key]);
83+
}
84+
}
85+
return mergedObj;
86+
}
7687
7788
const wrapShareModule = ${REMOTE_FROM_PARAMETER} => {
78-
return {
79-
${getModuleMarker('shareScope')}
80-
}
89+
return merge({
90+
${getModuleMarker('shareScope')}
91+
}, (globalThis.__federation_shared__ || {})['${shareScope}'] || {});
8192
}
8293
8394
async function __federation_import(name) {
@@ -109,7 +120,7 @@ export function prodRemotePlugin(
109120
getUrl().then(url => {
110121
import(/* @vite-ignore */ url).then(lib => {
111122
if (!remote.inited) {
112-
const shareScope = wrapShareModule(remote.from)
123+
const shareScope = wrapShareModule(remote.from);
113124
lib.init(shareScope);
114125
remote.lib = lib;
115126
remote.lib.init(shareScope);

0 commit comments

Comments
 (0)