Skip to content

Look up Fabric event handler prop names once per dispatch - #60537

Open
ide wants to merge 1 commit into
react:mainfrom
expo:@ide/fabric-event-dispatch
Open

ide wants to merge 1 commit into
react:mainfrom
expo:@ide/fabric-event-dispatch

Conversation

@ide

@ide ide commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

Native event dispatch reads the same handler prop name from the event at each target. Read the capture and bubble prop names once before traversing the path, and pass the name for each phase to the declarative listener lookup of each target. The lookup takes the name only from its caller, and uses the event type mapping when the event carries no name, as for events dispatched from JavaScript. Each target still reads its current props when invoking listeners.

Set the native timestamp in the event initializer and reuse a frozen empty path before and after dispatch.

Changelog:

[INTERNAL] [CHANGED] - Reuse handler prop names during Fabric event dispatch.

Test Plan:

yarn fantom passes for the suites under src/private/renderer and src/private/webapis/dom, including EventDispatching-itest.js, EventTargetDispatching-itest.js, EventTarget-itest.js and Event-itest.js. These suites cover capture, bubbling, propagation stops, listener errors and custom timestamps. A new case in EventTargetDispatching-itest.js dispatches an event from JavaScript and checks that the handler props along the path run in capture and bubble order; it fails when the lookup does not fall back to the event type mapping. yarn flow-check, yarn lint and yarn test for the touched directories pass, and the changed files pass Prettier.

A Fantom benchmark dispatches pointer-up events with Hermes on a stable tree of 20 levels, in an optimized Fantom tester build on Apple M6. For batches of 5,000 dispatches, the median falls from 1,353,503 to 1,076,197 retired instructions per event. Both versions make the same number of handler calls.

@github-actions github-actions Bot added the Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. label Dec 4, 2026
@ide
ide force-pushed the @ide/fabric-event-dispatch branch from 79342bc to 5ff88c0 Compare December 4, 2026 11:32
@ide ide changed the title Resolve native event properties once per dispatch Look up Fabric event handler prop names once per dispatch Dec 4, 2026
@ide
ide force-pushed the @ide/fabric-event-dispatch branch 3 times, most recently from 6f272fa to 78d8d80 Compare December 4, 2026 14:51
@ide
ide marked this pull request as ready for review December 4, 2026 16:24
@javache
javache requested a review from rubennorte December 4, 2026 18:16

@chrfalch chrfalch left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change keeps dispatch behavior the same: the prop names are fixed for the whole dispatch, each target still reads its current props, and the timestamp, direct-event and composed-path changes match the old results (composedPath() still returns a copy, so the frozen empty array never reaches user code). The two comments below are about clarity, not correctness. The test plan lists Fantom and Prettier but not yarn flow-check. Please add it, because the event init object now uses a computed symbol key in place of setEventInitTimeStamp, and ReactNativeElement adds a new $FlowExpectedError suppression.

Native event dispatch reads the same handler prop name from the event at each target. Read the capture and bubble prop names once before traversing the path, and pass the name for each phase to the declarative listener lookup of each target. The lookup takes the name only from its caller, and uses the event type mapping when the event carries no name, as for events dispatched from JavaScript. Each target still reads its current props when invoking listeners.

Set the native timestamp in the event initializer and reuse a frozen empty path before and after dispatch.

`yarn fantom` passes for the suites under `src/private/renderer` and `src/private/webapis/dom`, including `EventDispatching-itest.js`, `EventTargetDispatching-itest.js`, `EventTarget-itest.js` and `Event-itest.js`. These suites cover capture, bubbling, propagation stops, listener errors and custom timestamps. A new case in `EventTargetDispatching-itest.js` dispatches an event from JavaScript and checks that the handler props along the path run in capture and bubble order; it fails when the lookup does not fall back to the event type mapping. `yarn flow-check`, `yarn lint` and `yarn test` for the touched directories pass, and the changed files pass Prettier.

A Fantom benchmark dispatches pointer-up events with Hermes on a stable tree of 20 levels, in an optimized Fantom tester build on Apple M6. For batches of 5,000 dispatches, the median falls from 1,353,503 to 1,076,197 retired instructions per event. Both versions make the same number of handler calls.

Signed-off-by: James Ide <ide@expo.dev>
@ide
ide force-pushed the @ide/fabric-event-dispatch branch from 78d8d80 to dab62a9 Compare December 5, 2026 08:43
@ide

ide commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. The test plan now lists yarn flow-check, which passes, along with yarn lint and yarn test for the touched directories. The event initializer still uses the computed EVENT_INIT_TIMESTAMP_KEY. The $FlowExpectedError[incompatible-use] on the inline props read in ReactNativeElement also stays; the reply on that line explains why the read stays inline.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants