Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .nx/version-plans/version-plan-1779082548000.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
__default__: patch
---

Harness now keeps the browser's native `Event` and `EventTarget` on web, while still applying the shim where React Native needs it, so web users no longer lose native DOM behavior.
15 changes: 12 additions & 3 deletions packages/runtime/src/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@ import { getClient } from './client/index.js';
import { disableHMRWhenReady } from './disableHMRWhenReady.js';
import { setupJestMock } from './jest-mock.js';

// Polyfill for EventTarget
// Polyfill for EventTarget on runtimes that don't ship one (RN's JSC).
// Do NOT overwrite when a native ctor already exists (RN Web / browsers):
// Safari's EventTarget.dispatchEvent() does an internal brand check and
// rejects polyfill instances with a TypeError, which breaks any
// DOM-event-driven flow in the page — most visibly DRM (FairPlay) via
// libraries that re-dispatch synthetic `encrypted` events.
const Shim = require('event-target-shim');
globalThis.Event = Shim.Event;
globalThis.EventTarget = Shim.EventTarget;
if (typeof globalThis.Event !== 'function') {
globalThis.Event = Shim.Event;
}
if (typeof globalThis.EventTarget !== 'function') {
globalThis.EventTarget = Shim.EventTarget;
}

// Setup jest mock to warn users about using Jest APIs
setupJestMock();
Expand Down
Loading