arialpew / bs-dynamic-import

📦🚀 BuckleScript dynamic import interop on JavaScript environment
https://npmjs.com/bs-dynamic-import
MIT License
31 stars 1 forks source link

Error handling if bundle fails to load (React Error Boundaries) #16

Closed kd4001 closed 4 years ago

kd4001 commented 4 years ago

In React we can handle this by React Error Boundaries. https://reactjs.org/docs/error-boundaries.html

Something similar can be done here too to catch the error if any chunk fails.

arialpew commented 4 years ago

React Error Boundaries require class component, there's no official hook for this feature at the moment, but I guess you can use this package : https://www.npmjs.com/package/use-error-boundary

Warning : This package (bs-dynamic-import) is now in read-only mode, if you want to lazy load React components in a ReasonML application use "reason-loadable".

If you want to import something else like a JSON document or JavaScript code that isn't a React component (example : Math library), take a look at "reason-loadable" source code and tests, it can do that with some adaptation.

This package (bs-dynamic-import) probably doesn't work anymore since BuckleScript changed object representation in JavaScript output in recent version (from array to object).