diff --git a/.changeset/rude-trees-ring.md b/.changeset/rude-trees-ring.md new file mode 100644 index 0000000000..9f16cc0a27 --- /dev/null +++ b/.changeset/rude-trees-ring.md @@ -0,0 +1,5 @@ +--- +'@module-federation/runtime': patch +--- + +fix(runtime): set loading if registeredShared not set diff --git a/packages/runtime/__tests__/shares.spec.ts b/packages/runtime/__tests__/shares.spec.ts index 5a4ea2344b..bf5d0686ef 100644 --- a/packages/runtime/__tests__/shares.spec.ts +++ b/packages/runtime/__tests__/shares.spec.ts @@ -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); }); diff --git a/packages/runtime/src/shared/index.ts b/packages/runtime/src/shared/index.ts index d4e22b49c4..a800d7a6f4 100644 --- a/packages/runtime/src/shared/index.ts +++ b/packages/runtime/src/shared/index.ts @@ -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; } }); } diff --git a/packages/sdk/src/types/plugins/ModuleFederationPlugin.ts b/packages/sdk/src/types/plugins/ModuleFederationPlugin.ts index 896fe54426..5ffa3b16fb 100644 --- a/packages/sdk/src/types/plugins/ModuleFederationPlugin.ts +++ b/packages/sdk/src/types/plugins/ModuleFederationPlugin.ts @@ -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. diff --git a/packages/storybook-addon/src/lib/storybook-addon.ts b/packages/storybook-addon/src/lib/storybook-addon.ts index 939e56177c..e153c91186 100644 --- a/packages/storybook-addon/src/lib/storybook-addon.ts +++ b/packages/storybook-addon/src/lib/storybook-addon.ts @@ -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)); }