Skip to content

Commit 9f98292

Browse files
authored
fix(runtime): set loading if registeredShared not set (#2943)
1 parent 2394e38 commit 9f98292

File tree

5 files changed

+24
-14
lines changed

5 files changed

+24
-14
lines changed

.changeset/rude-trees-ring.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+
fix(runtime): set loading if registeredShared not set

packages/runtime/__tests__/shares.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ describe('shared', () => {
169169
const reactInstance2Res = reactInstance2();
170170
assert(reactInstance1Res, "reactInstance1 can't be undefined");
171171
assert(reactInstance2Res, "reactInstance2 can't be undefined");
172-
expect(reactInstance1Res.uniqueId).toBe(2);
173-
expect(reactInstance2Res.uniqueId).toBe(2);
172+
expect(reactInstance1Res.uniqueId).toBe(1);
173+
expect(reactInstance2Res.uniqueId).toBe(1);
174174
expect(reactInstance1Res).toStrictEqual(reactInstance2Res);
175175
});
176176

packages/runtime/src/shared/index.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -483,21 +483,24 @@ export class SharedHandler {
483483
this.shareScopeMap[sc][pkgName] = {};
484484
}
485485

486-
if (this.shareScopeMap[sc][pkgName][version]) {
486+
if (!this.shareScopeMap[sc][pkgName][version]) {
487+
this.shareScopeMap[sc][pkgName][version] = {
488+
version,
489+
scope: ['default'],
490+
...shareInfo,
491+
lib,
492+
loaded,
493+
loading,
494+
};
495+
if (get) {
496+
this.shareScopeMap[sc][pkgName][version].get = get;
497+
}
487498
return;
488499
}
489500

490-
this.shareScopeMap[sc][pkgName][version] = {
491-
version,
492-
scope: ['default'],
493-
...shareInfo,
494-
lib,
495-
loaded,
496-
loading,
497-
};
498-
499-
if (get) {
500-
this.shareScopeMap[sc][pkgName][version].get = get;
501+
const registeredShared = this.shareScopeMap[sc][pkgName][version];
502+
if (loading && !registeredShared.loading) {
503+
registeredShared.loading = loading;
501504
}
502505
});
503506
}

packages/sdk/src/types/plugins/ModuleFederationPlugin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export type ExternalsType =
8282
| 'promise'
8383
| 'import'
8484
| 'script'
85+
| 'module-import'
8586
| 'node-commonjs';
8687
/**
8788
* Container locations and request scopes from which modules should be resolved and loaded at runtime. When provided, property name is used as request scope, otherwise request scope is automatically inferred from container location.

packages/storybook-addon/src/lib/storybook-addon.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export const webpack = async (
5757

5858
if (moduleFederationConfig) {
5959
logger.info(`=> [MF] Push Module Federation plugin`);
60+
// @ts-ignore enhanced add new remoteType 'module-import'
6061
plugins.push(new ModuleFederationPlugin(moduleFederationConfig));
6162
}
6263

0 commit comments

Comments
 (0)