retryableImport.tsx 468 B

1234567891011121314151617181920212223
  1. import {isWebpackChunkLoadingError} from 'sentry/utils';
  2. const MAX_RETRIES = 2;
  3. export default function retryableImport<T>(
  4. fn: () => Promise<{default: T}>
  5. ): Promise<{default: T}> {
  6. let retries = 0;
  7. const tryLoad = async () => {
  8. try {
  9. return await fn();
  10. } catch (err) {
  11. if (isWebpackChunkLoadingError(err) && retries < MAX_RETRIES) {
  12. retries++;
  13. return tryLoad();
  14. }
  15. throw err;
  16. }
  17. };
  18. return tryLoad();
  19. }