Skip to content

Commit 2dafc35

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 2dafc35

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

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

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ 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;
57-
5853
_bubbles: boolean;
5954
_cancelable: boolean;
6055
_composed: boolean;
@@ -70,7 +65,7 @@ export default class Event {
7065
[CURRENT_TARGET_KEY]: EventTarget | null = null;
7166

7267
// $FlowExpectedError[unsupported-syntax]
73-
[EVENT_PHASE_KEY]: boolean = Event.NONE;
68+
[EVENT_PHASE_KEY]: boolean = 0;
7469

7570
// $FlowExpectedError[unsupported-syntax]
7671
[IN_PASSIVE_LISTENER_FLAG_KEY]: boolean = false;
@@ -193,48 +188,64 @@ export default class Event {
193188

194189
// $FlowExpectedError[cannot-write]
195190
Object.defineProperty(Event, 'NONE', {
191+
writable: true,
192+
configurable: true,
196193
enumerable: true,
197194
value: 0,
198195
});
199196

200197
// $FlowExpectedError[cannot-write]
201198
Object.defineProperty(Event.prototype, 'NONE', {
199+
writable: true,
200+
configurable: true,
202201
enumerable: true,
203202
value: 0,
204203
});
205204

206205
// $FlowExpectedError[cannot-write]
207206
Object.defineProperty(Event, 'CAPTURING_PHASE', {
207+
writable: true,
208+
configurable: true,
208209
enumerable: true,
209210
value: 1,
210211
});
211212

212213
// $FlowExpectedError[cannot-write]
213214
Object.defineProperty(Event.prototype, 'CAPTURING_PHASE', {
215+
writable: true,
216+
configurable: true,
214217
enumerable: true,
215218
value: 1,
216219
});
217220

218221
// $FlowExpectedError[cannot-write]
219222
Object.defineProperty(Event, 'AT_TARGET', {
223+
writable: true,
224+
configurable: true,
220225
enumerable: true,
221226
value: 2,
222227
});
223228

224229
// $FlowExpectedError[cannot-write]
225230
Object.defineProperty(Event.prototype, 'AT_TARGET', {
231+
writable: true,
232+
configurable: true,
226233
enumerable: true,
227234
value: 2,
228235
});
229236

230237
// $FlowExpectedError[cannot-write]
231238
Object.defineProperty(Event, 'BUBBLING_PHASE', {
239+
writable: true,
240+
configurable: true,
232241
enumerable: true,
233242
value: 3,
234243
});
235244

236245
// $FlowExpectedError[cannot-write]
237246
Object.defineProperty(Event.prototype, 'BUBBLING_PHASE', {
247+
writable: true,
248+
configurable: true,
238249
enumerable: true,
239250
value: 3,
240251
});

0 commit comments

Comments
 (0)