Expose Event, EventTarget and CustomEvent as globals (#56416)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/56416

Registers Event, EventTarget and CustomEvent as global polyfills in `setUpDOM.js`. These are standard Web APIs that DOM nodes need access to.

Removes the Event/EventTarget polyfills from the Fantom test setup since they are now provided globally by setUpDOM.js.

Changelog: [internal]

Marking as internal for now, until we ship to stable, even though this isn't gated. We shouldn't communicate this yet.

Reviewed By: javache

Differential Revision: D100462548

fbshipit-source-id: 3e30be760d4f524ca823ebf1320d9a607abeabf9
This commit is contained in:
Rubén Norte authored and meta-codesync[bot] committed 2026-04-13 03:55:39 -07:00
1 parent 2e508b9c82
commit f0f6240d1e
2 files changed
+12 -22

No files matched your search

+12
View File
@@ -73,4 +73,16 @@ export default function setUpDOM() {
'HTMLElement',
() => require('../webapis/dom/nodes/ReactNativeElement').default,
);
polyfillGlobal('Event', () => require('../webapis/dom/events/Event').default);
polyfillGlobal(
'EventTarget',
() => require('../webapis/dom/events/EventTarget').default,
);
polyfillGlobal(
'CustomEvent',
() => require('../webapis/dom/events/CustomEvent').default,
);
}
-22
View File
@@ -712,26 +712,4 @@ function getNode(nodeOrRef: NodeOrRef): ReadOnlyNode {
}
}
/**
* Quick and dirty polyfills required by tinybench.
*/
if (typeof global.Event === 'undefined') {
global.Event =
require('react-native/src/private/webapis/dom/events/Event').default;
} else {
console.warn(
'The global Event class is already defined. If this API is already defined by React Native, you might want to remove this logic.',
);
}
if (typeof global.EventTarget === 'undefined') {
global.EventTarget =
require('react-native/src/private/webapis/dom/events/EventTarget').default;
} else {
console.warn(
'The global Event class is already defined. If this API is already defined by React Native, you might want to remove this logic.',
);
}
global.__FANTOM_PACKAGE_LOADED__ = true;