From 43554b5a0f88bc1a8f267bc45100537a8d9c0f5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Wed, 20 Nov 2024 10:00:48 -0800 Subject: [PATCH] Expose NodeList and MutationRecord in global scope (#47759) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/47759 Changelog: [internal] These interfaces should be available in the global scope, so this exposes them in their setup modules. Reviewed By: javache Differential Revision: D66232574 fbshipit-source-id: 191c579ffce3fb8b4b454b5c5725661ff160a46f --- .../src/private/setup/setUpDOM.js | 20 +++++++++++++------ .../private/setup/setUpMutationObserver.js | 5 +++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/packages/react-native/src/private/setup/setUpDOM.js b/packages/react-native/src/private/setup/setUpDOM.js index 04f12e49dd6..f815c86c4e8 100644 --- a/packages/react-native/src/private/setup/setUpDOM.js +++ b/packages/react-native/src/private/setup/setUpDOM.js @@ -8,8 +8,7 @@ * @format */ -import DOMRect from '../webapis/dom/geometry/DOMRect'; -import DOMRectReadOnly from '../webapis/dom/geometry/DOMRectReadOnly'; +import {polyfillGlobal} from '../../../Libraries/Utilities/PolyfillFunctions'; let initialized = false; @@ -20,9 +19,18 @@ export default function setUpDOM() { initialized = true; - // $FlowExpectedError[cannot-write] The global isn't writable anywhere but here, where we define it - global.DOMRect = DOMRect; + polyfillGlobal( + 'DOMRect', + () => require('../webapis/dom/geometry/DOMRect').default, + ); - // $FlowExpectedError[cannot-write] The global isn't writable anywhere but here, where we define it - global.DOMRectReadOnly = DOMRectReadOnly; + polyfillGlobal( + 'DOMRectReadOnly', + () => require('../webapis/dom/geometry/DOMRectReadOnly').default, + ); + + polyfillGlobal( + 'NodeList', + () => require('../webapis/dom/oldstylecollections/NodeList').default, + ); } diff --git a/packages/react-native/src/private/setup/setUpMutationObserver.js b/packages/react-native/src/private/setup/setUpMutationObserver.js index 387d893ab75..e3f03b59172 100644 --- a/packages/react-native/src/private/setup/setUpMutationObserver.js +++ b/packages/react-native/src/private/setup/setUpMutationObserver.js @@ -23,4 +23,9 @@ export default function setUpMutationObserver() { 'MutationObserver', () => require('../webapis/mutationobserver/MutationObserver').default, ); + + polyfillGlobal( + 'MutationRecord', + () => require('../webapis/mutationobserver/MutationRecord').default, + ); }