DEV Community

Discussion on: How to retry when React lazy fails

Collapse
 
maininfection profile image
Ricardo Machado •

Hi Guilherme,

The reason for failing to download might be related to a recent deployment which changes the chunk hash and/or order number.

Also, don't forget to return the retry on the catch. Otherwise whoever gets the first retry cannot get the rejected error.

nice helper 👍

Collapse
 
goenning profile image
Guilherme Oenning •

I don't think you need to do that. If the second retries fails, you get a new error, which is likely to be the same as the first retry error. But maybe I misunderstood your argument.

Collapse
 
maininfection profile image
Ricardo Machado •

Ahhh I mislooked the last retry line. It actually passes the resolve and reject from the initial promise.

👍

Collapse
 
debo07 profile image
Debajit Majumder •

Could you please elaborate on this - "The reason for failing to download might be related to a recent deployment which changes the chunk hash and/or order number."?

I believe I am facing similar issue where just after a new deployment I able to see blank page with this console error.

Uncaught (in promise) Error: Loading chunk 7 failed.
(missing: domain.com/js/vendors~module1.bund...)
at HTMLScriptElement.i (bootstrap:120)

Collapse
 
0xdevalias profile image
Glenn 'devalias' Grant •

I would suggest having a look at this blog and/or StackOverflow answer, as I feel they better describe the problem (and the 'why' of it), as well as providing some better solutions:

As Ricardo mentioned above in dev.to/maininfection/comment/727e this ChunkLoadError generally tends to happen when pushing new code, while the client's browser still has the old/outdated 'list of chunks' cached.

Collapse
 
rainydaydy profile image
董雨 •

when use contenthash, if your file don't change, but add a new route, the chunkId will change,so the bundle is change but the filename doesn't change, when load chunk 1, the resource's chunkId maybe 2, so load chunk failed