Skip to content

Commit a93aba2

Browse files
return proxy object when remote is offline
1 parent ba94bd4 commit a93aba2

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"public": true,
33
"name": "@module-federation/nextjs-ssr",
4-
"version": "0.0.6-beta.0",
4+
"version": "0.0.6-beta.1",
55
"description": "Module Federation CSR & SSR Support for Next.js",
66
"main": "bundle.js",
77
"types": "index.d.ts",

streaming/src/NodeModuleFederation/index.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,20 @@ const executeLoadTemplate = `
1717
}).catch((e)=>{
1818
console.error('failed to fetch remote', moduleName, scriptUrl);
1919
console.error(e);
20-
reject(null)
20+
reject(null)
2121
})
22-
});
22+
}).catch(()=>{
23+
console.warn(moduleName,'is offline, returning fake remote')
24+
return {
25+
fake: true,
26+
get:(arg)=>{
27+
console.log('faking', arg,'module on', moduleName);
28+
29+
return ()=> Promise.resolve();
30+
},
31+
init:()=>{}
32+
}
33+
})
2334
}
2435
`;
2536

@@ -59,16 +70,20 @@ function buildRemotes(mfConf, webpack) {
5970
})
6071
})
6172
.then(function(remote){
62-
63-
const proxy= {
73+
const proxy= {
6474
get: remote.get,
6575
chunkMap: remote.chunkMap,
6676
path: "${config}",
6777
init:(arg)=>{
6878
try {
69-
return remote.init(shareScope.default)
79+
return remote.init(shareScope.default)
7080
} catch(e){console.log('remote container already initialized')}}
7181
}
82+
83+
if(remote.fake) {
84+
res(proxy);
85+
return null
86+
}
7287
Object.assign(global.loadedRemotes,{${JSON.stringify(name)}: proxy});
7388
7489
res(global.loadedRemotes[${JSON.stringify(name)}])

0 commit comments

Comments
 (0)