mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Refactor setup modules in src/private/setup as side-effect free modules (#45795)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/45795 Changelog: [internal] Our modules to set up the runtime have side-effects and depend on import order to work correctly. This is error-prone and complicates the migration to ESM in some cases, so this refactors all of them in `src/private/setup` to export a function instead. Reviewed By: rshest Differential Revision: D60382506 fbshipit-source-id: 9ac30b29659b74605d59eb97562d6cbf01f48e47
This commit is contained in:
committed by
Facebook GitHub Bot
parent
b74c4f6643
commit
48421df60a
+1
-1
@@ -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');
|
||||
|
||||
+14
-4
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user