Browse Source

chore: Extract requestIdleCallback shim to it's own file (#51212)

https://developer.mozilla.org/en-US/docs/Web/API/Window/requestIdleCallback
Ryan Albrecht 1 year ago
parent
commit
650f401be7

+ 1 - 14
static/app/utils/replays/extractDomNodes.tsx

@@ -4,6 +4,7 @@ import {EventType, Replayer} from '@sentry-internal/rrweb';
 import first from 'lodash/first';
 
 import type {Crumb} from 'sentry/types/breadcrumbs';
+import requestIdleCallback from 'sentry/utils/window/requestIdleCallback';
 
 export type Extraction = {
   crumb: Crumb;
@@ -17,20 +18,6 @@ type Args = {
   rrwebEvents: eventWithTime[] | undefined;
 };
 
-const requestIdleCallback =
-  window.requestIdleCallback ||
-  function requestIdleCallbackPolyfill(cb) {
-    const start = Date.now();
-    return setTimeout(function () {
-      cb({
-        didTimeout: false,
-        timeRemaining: function () {
-          return Math.max(0, 50 - (Date.now() - start));
-        },
-      });
-    }, 1);
-  };
-
 function _extractDomNodes({
   crumbs,
   rrwebEvents,

+ 15 - 0
static/app/utils/window/requestIdleCallback.tsx

@@ -0,0 +1,15 @@
+const requestIdleCallback =
+  window.requestIdleCallback ||
+  function requestIdleCallbackPolyfill(cb) {
+    const start = Date.now();
+    return setTimeout(function () {
+      cb({
+        didTimeout: false,
+        timeRemaining: function () {
+          return Math.max(0, 50 - (Date.now() - start));
+        },
+      });
+    }, 1);
+  };
+
+export default requestIdleCallback;