Skip to content

Commit

Permalink
fix: skip record remotes while the entry is legacy (#2748)
Browse files Browse the repository at this point in the history
Co-authored-by: Zack Jackson <zackary.l.jackson@gmail.com>
  • Loading branch information
2heal1 and ScriptedAlchemy authored Jul 10, 2024
1 parent e38e48d commit 4488064
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/green-chefs-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@module-federation/enhanced': patch
---

fix: intercept legacy entry
23 changes: 22 additions & 1 deletion apps/runtime-demo/3005-runtime-host/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,28 @@ module.exports = composePlugins(withNx(), withReact(), (config, context) => {
name: 'runtime_host',
remotes: {
// remote2: 'runtime_remote2@http://localhost:3007/remoteEntry.js',
remote1: 'runtime_remote1@http://127.0.0.1:3006/mf-manifest.json',
// remote1: 'runtime_remote1@http://127.0.0.1:3006/mf-manifest.json',
remote1: `promise new Promise((resolve)=>{
const raw = 'runtime_remote1@http://127.0.0.1:3006/remoteEntry.js'
const [_, remoteUrlWithVersion] = raw.split('@')
const script = document.createElement('script')
script.src = remoteUrlWithVersion
script.onload = () => {
const proxy = {
get: (request) => window.runtime_remote1.get(request),
init: (arg) => {
try {
return window.runtime_remote1.init(arg)
} catch(e) {
console.log('runtime_remote1 container already initialized')
}
}
}
resolve(proxy)
}
document.head.appendChild(script);
})`,
},
// library: { type: 'var', name: 'runtime_remote' },
filename: 'remoteEntry.js',
Expand Down
4 changes: 4 additions & 0 deletions packages/enhanced/src/lib/container/runtime/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ export function normalizeRuntimeInitOptionsWithOutShared(
const { external, shareScope } = remoteInfos;
try {
// only fit for remoteType: 'script'
const entry = external[0];
if (/\s/.test(entry)) {
return;
}
const [url, globalName] = extractUrlAndGlobal(external[0]);
remoteOptions.push({
alias,
Expand Down

0 comments on commit 4488064

Please sign in to comment.