Commit b7a0a12
fix(runtime): don't overwrite native Event/EventTarget on web
The runtime's initialize hook unconditionally replaces globalThis.Event
and globalThis.EventTarget with event-target-shim's classes. That's
necessary on RN's JSC runtime (no DOM), but on web (RN Web running in a
real browser) it stomps on the browser's native ctors.
Safari's native EventTarget.dispatchEvent() does an internal brand
check on its argument and throws
TypeError: Argument 1 ('event') to EventTarget.dispatchEvent must be
an instance of Event
when a polyfill instance is dispatched on a native EventTarget — even
though the polyfill mostly behaves like Event. That's enough to break
any DOM-event-driven flow in the page; the visible casualty was
FairPlay playback through @castlabs/react-native-prestoplay, where
AppleEmeManager re-dispatches a synthetic `encrypted` event onto the
<video> in response to `webkitneedkey` and Safari rejects it.
Gate both assignments on whether a native ctor is already present so
the polyfill only takes effect on platforms that genuinely lack one.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 64a74d7 commit b7a0a12
1 file changed
Lines changed: 12 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
7 | 12 | | |
8 | | - | |
9 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
10 | 19 | | |
11 | 20 | | |
12 | 21 | | |
| |||
0 commit comments