I am using the react Loadable Components Package to lazily load components in my react app as shown in the snippet below:
import loadable from '@loadable/component'
const OtherComponent = loadable(() => import('./OtherComponent'))
function MyComponent() {
return (
<div>
<OtherComponent />
</div>
)
}
The site is hosted on firebase hosting.
I noticed that sometimes the lazily imported component won't load until the page is refreshed manually.
On checking the logs I can see errors like
Chunk Failed to load
Once I refresh the page, the page gets loaded and the Chunk Failed to Load error is gone.
Is there a way to avoid this?
You can have a
retry(...)
function. It wont make the problem completely disappear, but at least it will add some resilience upon failures:Than you can use it like this (with the default options):