fix: make Event phase constants writable/configurable to prevent TypeError#57199
Open
IsaacIsrael wants to merge 1 commit into
Open
fix: make Event phase constants writable/configurable to prevent TypeError#57199IsaacIsrael wants to merge 1 commit into
IsaacIsrael wants to merge 1 commit into
Conversation
…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>
5f3593f to
2dafc35
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #54732
The
Eventclass insrc/private/webapis/dom/events/Event.jsdefinesNONE,CAPTURING_PHASE,AT_TARGET, andBUBBLING_PHASEas bothreadonlyinstance fields and viaObject.definePropertywithoutwritable/configurableflags. When Hermes compiles these class fields, they become non-writable/non-configurable properties, causing aTypeErrorat instantiation time:This crashes whenever a WebSocket event fires (Metro dev connection, push notifications), and the unhandled
TypeErrorpropagates into any concurrent Promise chain — breakingfetch()uploads and other network operations.Changes
Remove
readonlyfrom 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.Add
writable: true, configurable: trueto all 8Object.definePropertycalls — allowsevent-target-shim(used byabort-controller/fetch()) to redefine these properties when needed.Replace
Event.NONEinitializer with literal0— the[EVENT_PHASE_KEY]field initializer was referencingEvent.NONEbeforeObject.definePropertydefines 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
fetch()request or open a WebSocket connectionTypeError: Cannot assign to read-only property 'NONE'is thrownevent.NONE === 0,event.CAPTURING_PHASE === 1,event.AT_TARGET === 2,event.BUBBLING_PHASE === 3still hold on Event instances