Skip to content

Commit

Permalink
fix(runtime): set loading if registeredShared not set (#2943)
Browse files Browse the repository at this point in the history
  • Loading branch information
2heal1 authored Sep 11, 2024
1 parent 2394e38 commit 9f98292
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/rude-trees-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@module-federation/runtime': patch
---

fix(runtime): set loading if registeredShared not set
4 changes: 2 additions & 2 deletions packages/runtime/__tests__/shares.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ describe('shared', () => {
const reactInstance2Res = reactInstance2();
assert(reactInstance1Res, "reactInstance1 can't be undefined");
assert(reactInstance2Res, "reactInstance2 can't be undefined");
expect(reactInstance1Res.uniqueId).toBe(2);
expect(reactInstance2Res.uniqueId).toBe(2);
expect(reactInstance1Res.uniqueId).toBe(1);
expect(reactInstance2Res.uniqueId).toBe(1);
expect(reactInstance1Res).toStrictEqual(reactInstance2Res);
});

Expand Down
27 changes: 15 additions & 12 deletions packages/runtime/src/shared/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,21 +483,24 @@ export class SharedHandler {
this.shareScopeMap[sc][pkgName] = {};
}

if (this.shareScopeMap[sc][pkgName][version]) {
if (!this.shareScopeMap[sc][pkgName][version]) {
this.shareScopeMap[sc][pkgName][version] = {
version,
scope: ['default'],
...shareInfo,
lib,
loaded,
loading,
};
if (get) {
this.shareScopeMap[sc][pkgName][version].get = get;
}
return;
}

this.shareScopeMap[sc][pkgName][version] = {
version,
scope: ['default'],
...shareInfo,
lib,
loaded,
loading,
};

if (get) {
this.shareScopeMap[sc][pkgName][version].get = get;
const registeredShared = this.shareScopeMap[sc][pkgName][version];
if (loading && !registeredShared.loading) {
registeredShared.loading = loading;
}
});
}
Expand Down
1 change: 1 addition & 0 deletions packages/sdk/src/types/plugins/ModuleFederationPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export type ExternalsType =
| 'promise'
| 'import'
| 'script'
| 'module-import'
| 'node-commonjs';
/**
* 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.
Expand Down
1 change: 1 addition & 0 deletions packages/storybook-addon/src/lib/storybook-addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export const webpack = async (

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

Expand Down

0 comments on commit 9f98292

Please sign in to comment.