Skip to content

Commit 4488064

Browse files
fix: skip record remotes while the entry is legacy (#2748)
Co-authored-by: Zack Jackson <[email protected]>
1 parent e38e48d commit 4488064

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

.changeset/green-chefs-crash.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/enhanced': patch
3+
---
4+
5+
fix: intercept legacy entry

apps/runtime-demo/3005-runtime-host/webpack.config.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,28 @@ module.exports = composePlugins(withNx(), withReact(), (config, context) => {
1717
name: 'runtime_host',
1818
remotes: {
1919
// remote2: 'runtime_remote2@http://localhost:3007/remoteEntry.js',
20-
remote1: 'runtime_remote1@http://127.0.0.1:3006/mf-manifest.json',
20+
// remote1: 'runtime_remote1@http://127.0.0.1:3006/mf-manifest.json',
21+
remote1: `promise new Promise((resolve)=>{
22+
const raw = 'runtime_remote1@http://127.0.0.1:3006/remoteEntry.js'
23+
const [_, remoteUrlWithVersion] = raw.split('@')
24+
const script = document.createElement('script')
25+
script.src = remoteUrlWithVersion
26+
script.onload = () => {
27+
const proxy = {
28+
get: (request) => window.runtime_remote1.get(request),
29+
init: (arg) => {
30+
try {
31+
return window.runtime_remote1.init(arg)
32+
} catch(e) {
33+
console.log('runtime_remote1 container already initialized')
34+
}
35+
}
36+
}
37+
resolve(proxy)
38+
}
39+
document.head.appendChild(script);
40+
41+
})`,
2142
},
2243
// library: { type: 'var', name: 'runtime_remote' },
2344
filename: 'remoteEntry.js',

packages/enhanced/src/lib/container/runtime/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ export function normalizeRuntimeInitOptionsWithOutShared(
5151
const { external, shareScope } = remoteInfos;
5252
try {
5353
// only fit for remoteType: 'script'
54+
const entry = external[0];
55+
if (/\s/.test(entry)) {
56+
return;
57+
}
5458
const [url, globalName] = extractUrlAndGlobal(external[0]);
5559
remoteOptions.push({
5660
alias,

0 commit comments

Comments
 (0)