ctrlplusb / react-async-component

Resolve components asynchronously, with support for code splitting and advanced server side rendering use cases.
MIT License
1.45k stars 62 forks source link

Add a method to retry resolution and pass it to error component #70

Open nathanstitt opened 6 years ago

nathanstitt commented 6 years ago

I use react-async-component for loading web pack modules with import() and find that they sometimes will timeout or otherwise fail to load.

I'd like to add a button to my ErrorComponent but there wasn't a way to do so. This provides a function that could be called.

I've tested with simulated network timeout by putting Chrome offline and seems to work well.

I also added a spec and noticed a few things that could be improved there. Happy to rework if you spot anything else.

codecov[bot] commented 6 years ago

Codecov Report

Merging #70 into master will increase coverage by 2.42%. The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #70      +/-   ##
=========================================
+ Coverage   94.38%   96.8%   +2.42%     
=========================================
  Files           3       3              
  Lines          89      94       +5     
  Branches       25      25              
=========================================
+ Hits           84      91       +7     
+ Misses          5       3       -2
Impacted Files Coverage Δ
src/asyncComponent.js 96.05% <100%> (+3.09%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 94fc382...80c276a. Read the comment docs.

hochem commented 6 years ago

Any updates on this PR? I have the same problem (failed components will never resolve once networking is up again) and I would like to have this feature in the lib.

mgreer commented 5 years ago

I implement this as an HOC wrapper around async, to retry with backoff: https://gist.github.com/mgreer/eb33c95d22cabcec22a26b28acacaa16 Happy to contribute this as an option in the lib too.