Skip to content

Rethrow event listener errors synchronously for native event dispatch (#57207)#57207

Open
rubennorte wants to merge 1 commit into
react:mainfrom
rubennorte:export-D108622141
Open

Rethrow event listener errors synchronously for native event dispatch (#57207)#57207
rubennorte wants to merge 1 commit into
react:mainfrom
rubennorte:export-D108622141

Conversation

@rubennorte

@rubennorte rubennorte commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Summary:

Under the EventTarget-based event dispatch path, an error thrown by an event handler (e.g. onPress, onScroll) was deferred to a new task via setTimeout(0) in reportListenerError. This diverged from the legacy plugin path, which collected the first listener error and rethrew it synchronously at the end of the dispatch (React's runEventsInBatch + rethrowCaughtError). As a result, handler errors escaped the synchronous dispatch flow — they were no longer catchable by React error boundaries or the native event call, and instead surfaced as deferred, uncaught global errors.

This restores the legacy contract for native event dispatch:

  • dispatchTrustedEvent gains an opt-in rethrowListenerErrors argument. dispatch() threads a per-dispatch error holder through invoke/invokeListeners; when the flag is set it records the first listener error and rethrows it synchronously after the event has been fully cleaned up.
  • The renderer's native event dispatch (dispatchNativeEvent) opts in, so listener errors propagate synchronously again. The responder lifecycle rethrowCaughtError() is moved into a finally so a pending responder error can never leak into a later dispatch if the normal dispatch throws.
  • The public dispatchEvent API and other EventTarget consumers (e.g. XMLHttpRequest) are unchanged: they keep the DOM contract of reporting listener errors to the global error handler without throwing.
  • Re-enabled the previously skipped event-dispatch error-handling integration tests so they run in both dispatch modes.

Changelog: [Internal]

Reviewed By: javache

Differential Revision: D108622141

@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 15, 2026
@meta-codesync

meta-codesync Bot commented Jun 15, 2026

Copy link
Copy Markdown

@rubennorte has exported this pull request. If you are a Meta employee, you can view the originating Diff in D108622141.

…react#57207)

Summary:
Pull Request resolved: react#57207

Under the EventTarget-based event dispatch path, an error thrown by an event handler (e.g. `onPress`, `onScroll`) was deferred to a new task via `setTimeout(0)` in `reportListenerError`. This diverged from the legacy plugin path, which collected the first listener error and rethrew it synchronously at the end of the dispatch (React's `runEventsInBatch` + `rethrowCaughtError`). As a result, handler errors escaped the synchronous dispatch flow — they were no longer catchable by React error boundaries or the native event call, and instead surfaced as deferred, uncaught global errors.

This restores the legacy contract for native event dispatch:

- `dispatchTrustedEvent` gains an opt-in `rethrowListenerErrors` argument. `dispatch()` threads a per-dispatch error holder through `invoke`/`invokeListeners`; when the flag is set it records the first listener error and rethrows it synchronously after the event has been fully cleaned up.
- The renderer's native event dispatch (`dispatchNativeEvent`) opts in, so listener errors propagate synchronously again. The responder lifecycle `rethrowCaughtError()` is moved into a `finally` so a pending responder error can never leak into a later dispatch if the normal dispatch throws.
- The public `dispatchEvent` API and other `EventTarget` consumers (e.g. `XMLHttpRequest`) are unchanged: they keep the DOM contract of reporting listener errors to the global error handler without throwing.
- Re-enabled the previously skipped event-dispatch error-handling integration tests so they run in both dispatch modes.

Changelog: [Internal]

Reviewed By: javache

Differential Revision: D108622141
@meta-codesync meta-codesync Bot changed the title Rethrow event listener errors synchronously for native event dispatch Rethrow event listener errors synchronously for native event dispatch (#57207) Jun 15, 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. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant