module-federation-examples icon indicating copy to clipboard operation
module-federation-examples copied to clipboard

feat(): add error handling when remote is down

Open infoxicator opened this issue 3 years ago • 1 comments

When app2 is down the entire app crashes. Since the route definition is synchronous and happens before the app renders, we can't do a dynamic import like const routes = await import('app2/routes') in order to catch the error so it has to be caught before the module federation promise rejects.

infoxicator avatar Aug 05 '22 16:08 infoxicator

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Aug 05 '22 16:08 CLAassistant

shpuld use webpack require. but ill send you the snippit tommorrow

ScriptedAlchemy avatar Aug 11 '22 06:08 ScriptedAlchemy

shpuld use webpack require. but ill send you the snippit tommorrow

I found another alternative where you can create a promise chain and resolve before the app i.e.

import('app2/routes').then(async (module) => {
    ReactDOM.render(<App routes={module.default} />, document.querySelector('#root'));
  }).catch(e => { 
// handle error or render App with fallback routes
}

But it would be great to have an example on how to use the low level API above to handle this on the script.onerror()

infoxicator avatar Aug 11 '22 10:08 infoxicator

@infoxicator is attempting to deploy a commit to the Module Federation Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Aug 24 '22 11:08 vercel[bot]