Commit 645f846
Re-throw event listener errors in a new task (#56760)
Summary:
Pull Request resolved: #56760
Aligns error handling in the new EventTarget-based event dispatch path with the legacy plugin path, which surfaces handler errors to the host's global error handler (rather than swallowing them as `console.error`).
Previously, when a React event handler threw, `EventTarget.invoke` caught the error and called `console.error(error)` — the error never reached the host's error reporter, so it was effectively silent in production builds that intercept `console.error`.
This diff replaces the `console.error` calls in `EventTarget.invoke` with a small `reportListenerError` helper that schedules the error to be re-thrown in a new task via `setTimeout(0)`. The throw has no catcher above it, so the host's unhandled-error reporter sees it — matching the legacy plugin path's `runEventsInBatch` + `rethrowCaughtError` behavior of propagating the first listener error after the dispatch batch completes. The dispatch loop itself continues normally so subsequent listeners (e.g. parent bubble handlers) still fire.
Updates the corresponding test in `EventTargetDispatching-itest.js` to drop the `console.error` mock setup that was specific to the old behavior. Both code paths now satisfy the same assertion (`expect(dispatch).toThrow('handler error')`) — the legacy path throws synchronously after the React batch; the new path's async re-throw surfaces inside Fantom's internal work-loop pump during `Fantom.dispatchNativeEvent`.
Changelog:
[Internal]
Reviewed By: javache
Differential Revision: D104650049
fbshipit-source-id: 793072f82c9abf11f4fad23b3c1f044f0e5d29361 parent 3790942 commit 645f846
2 files changed
Lines changed: 19 additions & 31 deletions
File tree
- packages/react-native/src/private
- renderer/core/__tests__
- webapis/dom/events
Lines changed: 1 addition & 27 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1322 | 1322 | | |
1323 | 1323 | | |
1324 | 1324 | | |
1325 | | - | |
1326 | | - | |
1327 | | - | |
1328 | | - | |
1329 | | - | |
1330 | | - | |
1331 | | - | |
1332 | | - | |
1333 | | - | |
1334 | | - | |
1335 | | - | |
1336 | | - | |
1337 | | - | |
1338 | | - | |
1339 | | - | |
1340 | 1325 | | |
1341 | 1326 | | |
1342 | 1327 | | |
| |||
1365 | 1350 | | |
1366 | 1351 | | |
1367 | 1352 | | |
1368 | | - | |
1369 | | - | |
1370 | | - | |
1371 | | - | |
1372 | | - | |
1373 | | - | |
1374 | | - | |
1375 | | - | |
1376 | | - | |
1377 | | - | |
1378 | | - | |
1379 | | - | |
| 1353 | + | |
1380 | 1354 | | |
1381 | 1355 | | |
1382 | 1356 | | |
| |||
Lines changed: 18 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
382 | 382 | | |
383 | 383 | | |
384 | 384 | | |
385 | | - | |
386 | | - | |
| 385 | + | |
387 | 386 | | |
388 | 387 | | |
389 | 388 | | |
| |||
452 | 451 | | |
453 | 452 | | |
454 | 453 | | |
455 | | - | |
456 | | - | |
| 454 | + | |
457 | 455 | | |
458 | 456 | | |
459 | 457 | | |
| |||
507 | 505 | | |
508 | 506 | | |
509 | 507 | | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
0 commit comments