Skip to content

Commit 5f3593f

Browse files
fix: make Event phase constants writable/configurable to prevent TypeError
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 #54732 Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 066c0d8 commit 5f3593f

1 file changed

Lines changed: 21 additions & 5 deletions

File tree

  • packages/react-native/src/private/webapis/dom/events

packages/react-native/src/private/webapis/dom/events/Event.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ export default class Event {
5050
static readonly AT_TARGET: 2;
5151
static readonly BUBBLING_PHASE: 3;
5252

53-
readonly NONE: 0;
54-
readonly CAPTURING_PHASE: 1;
55-
readonly AT_TARGET: 2;
56-
readonly BUBBLING_PHASE: 3;
53+
NONE: 0;
54+
CAPTURING_PHASE: 1;
55+
AT_TARGET: 2;
56+
BUBBLING_PHASE: 3;
5757

5858
_bubbles: boolean;
5959
_cancelable: boolean;
@@ -70,7 +70,7 @@ export default class Event {
7070
[CURRENT_TARGET_KEY]: EventTarget | null = null;
7171

7272
// $FlowExpectedError[unsupported-syntax]
73-
[EVENT_PHASE_KEY]: boolean = Event.NONE;
73+
[EVENT_PHASE_KEY]: boolean = 0;
7474

7575
// $FlowExpectedError[unsupported-syntax]
7676
[IN_PASSIVE_LISTENER_FLAG_KEY]: boolean = false;
@@ -193,48 +193,64 @@ export default class Event {
193193

194194
// $FlowExpectedError[cannot-write]
195195
Object.defineProperty(Event, 'NONE', {
196+
writable: true,
197+
configurable: true,
196198
enumerable: true,
197199
value: 0,
198200
});
199201

200202
// $FlowExpectedError[cannot-write]
201203
Object.defineProperty(Event.prototype, 'NONE', {
204+
writable: true,
205+
configurable: true,
202206
enumerable: true,
203207
value: 0,
204208
});
205209

206210
// $FlowExpectedError[cannot-write]
207211
Object.defineProperty(Event, 'CAPTURING_PHASE', {
212+
writable: true,
213+
configurable: true,
208214
enumerable: true,
209215
value: 1,
210216
});
211217

212218
// $FlowExpectedError[cannot-write]
213219
Object.defineProperty(Event.prototype, 'CAPTURING_PHASE', {
220+
writable: true,
221+
configurable: true,
214222
enumerable: true,
215223
value: 1,
216224
});
217225

218226
// $FlowExpectedError[cannot-write]
219227
Object.defineProperty(Event, 'AT_TARGET', {
228+
writable: true,
229+
configurable: true,
220230
enumerable: true,
221231
value: 2,
222232
});
223233

224234
// $FlowExpectedError[cannot-write]
225235
Object.defineProperty(Event.prototype, 'AT_TARGET', {
236+
writable: true,
237+
configurable: true,
226238
enumerable: true,
227239
value: 2,
228240
});
229241

230242
// $FlowExpectedError[cannot-write]
231243
Object.defineProperty(Event, 'BUBBLING_PHASE', {
244+
writable: true,
245+
configurable: true,
232246
enumerable: true,
233247
value: 3,
234248
});
235249

236250
// $FlowExpectedError[cannot-write]
237251
Object.defineProperty(Event.prototype, 'BUBBLING_PHASE', {
252+
writable: true,
253+
configurable: true,
238254
enumerable: true,
239255
value: 3,
240256
});

0 commit comments

Comments
 (0)