-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: retry lazy load components when server is down [WD-13909] #927
Conversation
src/util/lazyWithRetry.tsx
Outdated
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const lazyWithRetry = <T extends React.ComponentType<any>>( | ||
importFunction: () => Promise<{ default: T }>, | ||
retries = 3, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
de41344
to
568b6a0
Compare
568b6a0
to
0b929d9
Compare
0b929d9
to
10ed599
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to not work as expected. I blocked one of the js files manually with chrome dev tools and see only one request for the resource, where I would expect 3 network requests due to the retry.
Thanks for catching this! When I tested it, I debugged in the source file and didn't check the network requests! So it seems that the browser caches import responses, which means when we retry, it will use the cache first and hence you are not seeing the additional requests. I'm have an idea, but will need to investigate on the feasibility of the approach, looking into it. Edit: @edlerd so I pushed an approach, I would like to know what you think about it. Due to |
1ae63a8
to
298a5c9
Compare
If we have a way "auto-heal" I think it is worth the complexity as it is contained within on file. I think there is a bit simpler approach using recursion as described in this blog. Not sure if this one still works, but maybe we can adopt it here? |
Thanks for the resource :) I did see this one and tried it, most of the articles I've seen have similar recursive or iterative implementations. The problem is really that a dynamic import would cache successful or failed network requests i.e. |
Yes, reload should be avoided. I suspected the recursive approach might avoid the caching behaviour. |
Unfortunately not, caching happens within |
b1b6394
to
7b686b6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QA LGTM, nice approach :)
Some comments on the code and copy. should be very easy to address and then this should be good to merge.
Signed-off-by: Mason Hu <[email protected]>
7b686b6
to
881932d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Done
QA
lazyWithRetry
function.Screenshots