From a6dd18c2a6936b658016372ddb323f4be30cabc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Thu, 27 Feb 2025 03:07:54 -0800 Subject: [PATCH] Expose new DOM classes in the global scope (#49697) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/49697 Changelog: [internal] These classes cannot be instantiated directly, but having access to them allows users to do `instanceof` checks, e.g.: ``` if (ref.current instanceof Element) { ref.current.getBoundingClientRect(); } ``` Reviewed By: yungsters Differential Revision: D70244966 fbshipit-source-id: 3c1e3698b8851ef9ce3c2865e7435b000984c8f0 --- .../src/private/setup/setUpDOM.js | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/packages/react-native/src/private/setup/setUpDOM.js b/packages/react-native/src/private/setup/setUpDOM.js index a0bf36b1c45..a506401440c 100644 --- a/packages/react-native/src/private/setup/setUpDOM.js +++ b/packages/react-native/src/private/setup/setUpDOM.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict + * @flow strict-local * @format */ @@ -29,6 +29,11 @@ export default function setUpDOM() { () => require('../webapis/geometry/DOMRectReadOnly').default, ); + polyfillGlobal( + 'DOMRectList', + () => require('../webapis/geometry/DOMRectList').default, + ); + polyfillGlobal( 'HTMLCollection', () => require('../webapis/dom/oldstylecollections/HTMLCollection').default, @@ -38,4 +43,34 @@ export default function setUpDOM() { 'NodeList', () => require('../webapis/dom/oldstylecollections/NodeList').default, ); + + polyfillGlobal( + 'Node', + () => require('../webapis/dom/nodes/ReadOnlyNode').default, + ); + + polyfillGlobal( + 'Document', + () => require('../webapis/dom/nodes/ReactNativeDocument').default, + ); + + polyfillGlobal( + 'CharacterData', + () => require('../webapis/dom/nodes/ReadOnlyCharacterData').default, + ); + + polyfillGlobal( + 'Text', + () => require('../webapis/dom/nodes/ReadOnlyText').default, + ); + + polyfillGlobal( + 'Element', + () => require('../webapis/dom/nodes/ReadOnlyElement').default, + ); + + polyfillGlobal( + 'HTMLElement', + () => require('../webapis/dom/nodes/ReactNativeElement').default, + ); }