Skip to content

Commit 8671892

Browse files
authored
fix(chrome-devtools): fix sharedInfo conflict with userOptions.sharedInfo cause hmr fail (#2612)
1 parent 34f9498 commit 8671892

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

.changeset/little-pugs-lay.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/devtools': patch
3+
---
4+
5+
fix(chrome-devtools): fix sharedInfo conflict with userOptions.sharedInfo cause hmr fail

packages/chrome-devtools/src/utils/chrome/fast-refresh.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const fastRefreshPlugin = (): FederationRuntimePlugin => {
1313
name: 'mf-fast-refresh-plugin',
1414
beforeInit({ userOptions, ...args }) {
1515
const shareInfo = userOptions.shared;
16+
const twinsShareInfo = args.shareInfo;
1617
let enableFastRefresh: boolean;
1718
let devtoolsMessage;
1819

@@ -37,7 +38,15 @@ const fastRefreshPlugin = (): FederationRuntimePlugin => {
3738
? shareInfo[share]
3839
: [shareInfo[share]];
3940

40-
sharedArr.forEach((shared) => {
41+
let twinsSharedArr: Shared[];
42+
if (twinsShareInfo) {
43+
// @ts-expect-error
44+
twinsSharedArr = Array.isArray(twinsShareInfo[share])
45+
? twinsShareInfo[share]
46+
: [twinsShareInfo[share]];
47+
}
48+
49+
sharedArr.forEach((shared, idx) => {
4150
let get: () => any;
4251
if (share === 'react') {
4352
get = () =>
@@ -78,6 +87,9 @@ const fastRefreshPlugin = (): FederationRuntimePlugin => {
7887
return () => window.ReactDOM;
7988
};
8089
}
90+
if (twinsShareInfo) {
91+
twinsSharedArr[idx].get = shared.get;
92+
}
8193
}
8294
});
8395
});

0 commit comments

Comments
 (0)