getPreloadedData.ts 611 B

12345678910111213141516171819202122232425262728
  1. export async function getPreloadedDataPromise(
  2. name: string,
  3. slug: string,
  4. fallback: () => Promise<any>,
  5. isInitialFetch?: boolean
  6. ) {
  7. try {
  8. const data = (window as any).__sentry_preload;
  9. if (
  10. !isInitialFetch ||
  11. !data ||
  12. !data.orgSlug ||
  13. data.orgSlug.toLowerCase() !== slug.toLowerCase() ||
  14. !data[name] ||
  15. !data[name].then
  16. ) {
  17. return await fallback();
  18. }
  19. const result = await data[name].catch(fallback);
  20. if (!result) {
  21. return await fallback();
  22. }
  23. return await result;
  24. } catch (_) {
  25. //
  26. }
  27. return await fallback();
  28. }