Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runtime): set loading if registeredShared not set #2943

Merged
merged 3 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
this.shareScopeMap[sc][pkgName] = {};
}

if (this.shareScopeMap[sc][pkgName][version]) {
if (!this.shareScopeMap[sc][pkgName][version]) {
this.shareScopeMap[sc][pkgName][version] = {
Dismissed Show dismissed Hide dismissed
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;
}
Comment on lines +502 to 504
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider updating the condition to set loading even if registeredShared.loading is already set. This ensures that the most up-to-date loading state is always reflected. Here's a suggested change:

Suggested change
if (loading && !registeredShared.loading) {
registeredShared.loading = loading;
}
if (loading) {
registeredShared.loading = loading;
}

This modification allows the loading state to be updated even if it was previously set, which could be useful in scenarios where the loading state might change during the lifecycle of the shared module.

});
}
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
Loading