diff --git a/packages/react-native/Libraries/Core/InitializeCore.js b/packages/react-native/Libraries/Core/InitializeCore.js index fdbbb50634b..f01d96e0df1 100644 --- a/packages/react-native/Libraries/Core/InitializeCore.js +++ b/packages/react-native/Libraries/Core/InitializeCore.js @@ -29,7 +29,7 @@ const start = Date.now(); require('./setUpGlobals'); -require('../../src/private/setup/setUpDOM'); +require('../../src/private/setup/setUpDOM').default(); require('./setUpPerformance'); require('./setUpErrorHandling'); require('./polyfillPromise'); diff --git a/packages/react-native/src/private/setup/setUpDOM.js b/packages/react-native/src/private/setup/setUpDOM.js index 0a75bd8dab8..04f12e49dd6 100644 --- a/packages/react-native/src/private/setup/setUpDOM.js +++ b/packages/react-native/src/private/setup/setUpDOM.js @@ -11,8 +11,18 @@ import DOMRect from '../webapis/dom/geometry/DOMRect'; import DOMRectReadOnly from '../webapis/dom/geometry/DOMRectReadOnly'; -// $FlowExpectedError[cannot-write] The global isn't writable anywhere but here, where we define it -global.DOMRect = DOMRect; +let initialized = false; -// $FlowExpectedError[cannot-write] The global isn't writable anywhere but here, where we define it -global.DOMRectReadOnly = DOMRectReadOnly; +export default function setUpDOM() { + if (initialized) { + return; + } + + initialized = true; + + // $FlowExpectedError[cannot-write] The global isn't writable anywhere but here, where we define it + global.DOMRect = DOMRect; + + // $FlowExpectedError[cannot-write] The global isn't writable anywhere but here, where we define it + global.DOMRectReadOnly = DOMRectReadOnly; +} diff --git a/packages/react-native/src/private/setup/setUpIntersectionObserver.js b/packages/react-native/src/private/setup/setUpIntersectionObserver.js index 026f6415641..773a6d9f6d8 100644 --- a/packages/react-native/src/private/setup/setUpIntersectionObserver.js +++ b/packages/react-native/src/private/setup/setUpIntersectionObserver.js @@ -10,7 +10,18 @@ import {polyfillGlobal} from '../../../Libraries/Utilities/PolyfillFunctions'; -polyfillGlobal( - 'IntersectionObserver', - () => require('../webapis/intersectionobserver/IntersectionObserver').default, -); +let initialized = false; + +export default function setUpIntersectionObserver() { + if (initialized) { + return; + } + + initialized = true; + + polyfillGlobal( + 'IntersectionObserver', + () => + require('../webapis/intersectionobserver/IntersectionObserver').default, + ); +} diff --git a/packages/react-native/src/private/setup/setUpMutationObserver.js b/packages/react-native/src/private/setup/setUpMutationObserver.js index 00e1b7fd7fd..387d893ab75 100644 --- a/packages/react-native/src/private/setup/setUpMutationObserver.js +++ b/packages/react-native/src/private/setup/setUpMutationObserver.js @@ -10,7 +10,17 @@ import {polyfillGlobal} from '../../../Libraries/Utilities/PolyfillFunctions'; -polyfillGlobal( - 'MutationObserver', - () => require('../webapis/mutationobserver/MutationObserver').default, -); +let initialized = false; + +export default function setUpMutationObserver() { + if (initialized) { + return; + } + + initialized = true; + + polyfillGlobal( + 'MutationObserver', + () => require('../webapis/mutationobserver/MutationObserver').default, + ); +} diff --git a/packages/react-native/src/private/setup/setUpPerformanceObserver.js b/packages/react-native/src/private/setup/setUpPerformanceObserver.js index e4b03cf3bb4..4f304741f89 100644 --- a/packages/react-native/src/private/setup/setUpPerformanceObserver.js +++ b/packages/react-native/src/private/setup/setUpPerformanceObserver.js @@ -10,44 +10,54 @@ import {polyfillGlobal} from '../../../Libraries/Utilities/PolyfillFunctions'; -polyfillGlobal( - 'PerformanceObserver', - () => require('../webapis/performance/PerformanceObserver').default, -); +let initialized = false; -polyfillGlobal( - 'PerformanceObserverEntryList', - () => - require('../webapis/performance/PerformanceObserver') - .PerformanceObserverEntryList, -); +export default function setUpPerformanceObserver() { + if (initialized) { + return; + } -polyfillGlobal( - 'PerformanceEntry', - () => require('../webapis/performance/PerformanceEntry').PerformanceEntry, -); + initialized = true; -polyfillGlobal( - 'PerformanceMark', - () => require('../webapis/performance/UserTiming').PerformanceMark, -); + polyfillGlobal( + 'PerformanceObserver', + () => require('../webapis/performance/PerformanceObserver').default, + ); -polyfillGlobal( - 'PerformanceMeasure', - () => require('../webapis/performance/UserTiming').PerformanceMeasure, -); + polyfillGlobal( + 'PerformanceObserverEntryList', + () => + require('../webapis/performance/PerformanceObserver') + .PerformanceObserverEntryList, + ); -polyfillGlobal( - 'PerformanceEventTiming', - () => require('../webapis/performance/EventTiming').PerformanceEventTiming, -); + polyfillGlobal( + 'PerformanceEntry', + () => require('../webapis/performance/PerformanceEntry').PerformanceEntry, + ); -polyfillGlobal( - 'TaskAttributionTiming', - () => require('../webapis/performance/LongTasks').TaskAttributionTiming, -); + polyfillGlobal( + 'PerformanceMark', + () => require('../webapis/performance/UserTiming').PerformanceMark, + ); -polyfillGlobal( - 'PerformanceLongTaskTiming', - () => require('../webapis/performance/LongTasks').PerformanceLongTaskTiming, -); + polyfillGlobal( + 'PerformanceMeasure', + () => require('../webapis/performance/UserTiming').PerformanceMeasure, + ); + + polyfillGlobal( + 'PerformanceEventTiming', + () => require('../webapis/performance/EventTiming').PerformanceEventTiming, + ); + + polyfillGlobal( + 'TaskAttributionTiming', + () => require('../webapis/performance/LongTasks').TaskAttributionTiming, + ); + + polyfillGlobal( + 'PerformanceLongTaskTiming', + () => require('../webapis/performance/LongTasks').PerformanceLongTaskTiming, + ); +}