-
Notifications
You must be signed in to change notification settings - Fork 24.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Event and CustomEvent polyfills are missing after the Hermes migration? #38004
Comments
|
Update: I was able to resolve my situation using the following code: global.event = require("react-native/Libraries/Events/EventPolyfill").default; However, I would be interested to know why these aren't being exported and set by default in order to fully understand the tradeoffs of what I'm doing here. |
They were added as part of an experimental prototype of support for the EventTarget API, but were recently removed because we're going to redo that API properly at some point in the future. Sorry, but they were not meant for external consumptions |
Thank you @necolas. Will these continue to be importable for community use until an alternative polyfill is provided? They've allowed us to move forward for now and I'm not aware of any bugs yet. |
What are you using them for? |
A couple of critical sub dependencies were relying on Event / CustomEvent for us |
Without the EventTarget dispatching system, how are those polyfills useful? I'm assuming you have a multi-platform app with web dependencies or have been using another JS env with EventTarget implemented? I still don't understand how you're using these polyfills in an RN app |
@necolas Unfortunately the implementation details of the sub-dependency that was relying on One of our dependencies depends on it-parallel created by @achingbrain. Inside of const CustomEvent = globalThis.CustomEvent ?? Event; This does indeed use the EventTarget API. This package looks like its intended for both browser and node. I'm not sure I understand why this package is necessary when native JS APIs can probably accomplish all of what this package is doing. As for how we got away with using this without having EventTarget shimmed? Well it looks like it was necessary to get metro to bundle, but the codepath where EventTarget is undefined probably never gets hit. So you are correct that using this polyfill without EventTarget doesn't do much, other than allow us to compile with metro until the undefined bits get hit. I appreciate your taking the time to look at this issue. In the mean time, it sounds like React Native users need to shim all of EventTarget rather than just Event. While I've got you, are you aware of an Event / CustomEvent / EventTarget polyfill for use on RN? I see this one: https://github.com/mysticatea/event-target-shim but wanted to tap your expertise if you have any opinions. |
Your best option is to stop bundling this code in your native bundles. |
Hey @shamilovtim, did you manage to use the event-target-shim package you linked? I'm also trying to use a package which relies on EventTarget API, but no success so far. My app instantly crashes with this error: |
Hey @MaxAst I ended up using a community powered polyfill called event-target-polyfill |
Description
In 0.69.0, @JoshuaGross added polyfills for W3C Event and CustomEvent.
Now, as of RN 0.71.8 we're using Hermes on iOS and none of the following works:
Furthermore, neither
CustomEvent
norEvent
nor/EventPolyfill.js
seem to be part of the exported namespaces in the type definitions or package discovery so I was unable to try to auto-import these with my editor to see if I can force the implementation of the polyfills from the project myself.Some questions I have
React Native Version
0.71.8
Output of
npx react-native info
Steps to reproduce
Using Hermes on iOS:
Snack, code example, screenshot, or link to a repository
Using Hermes on iOS:
The text was updated successfully, but these errors were encountered: