Skip to content

fix: make Event phase constants writable/configurable to prevent TypeError#57199

Open
IsaacIsrael wants to merge 1 commit into
react:mainfrom
IsaacIsrael:fix/event-readonly-properties
Open

fix: make Event phase constants writable/configurable to prevent TypeError#57199
IsaacIsrael wants to merge 1 commit into
react:mainfrom
IsaacIsrael:fix/event-readonly-properties

Conversation

@IsaacIsrael

@IsaacIsrael IsaacIsrael commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #54732

The Event class in src/private/webapis/dom/events/Event.js defines NONE, CAPTURING_PHASE, AT_TARGET, and BUBBLING_PHASE as both readonly instance fields and via Object.defineProperty without writable/configurable flags. When Hermes compiles these class fields, they become non-writable/non-configurable properties, causing a TypeError at instantiation time:

TypeError: Cannot assign to read-only property 'NONE'
    at Event (Event.js:53:4)
    at anonymous (WebSocket.js:258:63)
    at apply (native)
    at emit (EventEmitter.js:130:7)

This crashes whenever a WebSocket event fires (Metro dev connection, push notifications), and the unhandled TypeError propagates into any concurrent Promise chain — breaking fetch() uploads and other network operations.

Changes

  1. Remove readonly from instance-level field declarations — the static properties are inherited via the prototype chain automatically, so explicit readonly instance declarations are unnecessary and cause the Hermes conflict.

  2. Add writable: true, configurable: true to all 8 Object.defineProperty calls — allows event-target-shim (used by abort-controller / fetch()) to redefine these properties when needed.

  3. Replace Event.NONE initializer with literal 0 — the [EVENT_PHASE_KEY] field initializer was referencing Event.NONE before Object.defineProperty defines it at the bottom of the file.

Changelog:

[GENERAL] [FIXED] - Fix TypeError "Cannot assign to read-only property 'NONE'" in Event class when using New Architecture with Hermes

Test Plan

  1. Create a React Native 0.85+ app with New Architecture enabled
  2. Make any fetch() request or open a WebSocket connection
  3. Verify no TypeError: Cannot assign to read-only property 'NONE' is thrown
  4. Verify event.NONE === 0, event.CAPTURING_PHASE === 1, event.AT_TARGET === 2, event.BUBBLING_PHASE === 3 still hold on Event instances

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 14, 2026
…Error

The Event class defines NONE, CAPTURING_PHASE, AT_TARGET, BUBBLING_PHASE
as readonly instance fields and via Object.defineProperty without
writable/configurable flags. Hermes compiles these as non-writable,
causing TypeError at instantiation: Cannot assign to read-only property NONE.

This crashes on WebSocket events and propagates into fetch uploads.

Fix: remove readonly from instance fields, add writable+configurable to
Object.defineProperty calls, replace Event.NONE initializer with literal 0.

Fixes react#54732

Co-authored-by: Cursor <cursoragent@cursor.com>
@IsaacIsrael IsaacIsrael force-pushed the fix/event-readonly-properties branch from 5f3593f to 2dafc35 Compare June 14, 2026 14:00
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Jun 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Event.NONE/CAPTURING_PHASE/AT_TARGET/BUBBLING_PHASE properties missing configurable: true breaks event-target-shim

1 participant