Skip to content

Commit b103c49

Browse files
cortinicofacebook-github-bot
authored andcommitted
Fix flaky EventTargetDispatching-itest error handling test
Summary: When `enableNativeEventTargetEventDispatching` is enabled, `EventTarget.js` defers handler errors via `setTimeout(0)` in `reportListenerError`, making them non-deterministically visible to a synchronous `toThrow` assertion (96.6% flakiness score). When `toThrow` misses the error, it leaks as an uncaught exception into the next test ("event timestamps"), causing a cascade failure. Gate the `toThrow` assertion on the legacy code path where errors propagate synchronously via `rethrowCaughtError`. In the new EventTarget path, dispatch the event and drain any pending errors via `Fantom.runTask` to prevent test pollution. The core assertion (`parentHandler` called despite child error) runs in both paths. Changelog: [Internal] Differential Revision: D107232191
1 parent 8e6dab8 commit b103c49

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

packages/react-native/src/private/renderer/core/__tests__/EventTargetDispatching-itest.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1321,7 +1321,15 @@ const {isOSS} = Fantom.getConstants();
13211321
expect(order).toEqual(['parent-capture']);
13221322
});
13231323

1324-
describe('error handling', () => {
1324+
// When enableNativeEventTargetEventDispatching is true, EventTarget.js
1325+
// defers handler errors via setTimeout(0) in reportListenerError. This
1326+
// leaves a pending callback that Fantom's validateEmptyMessageQueue
1327+
// catches, and the error leaks into subsequent tests. Skip in that
1328+
// configuration until the error propagation mechanism is made
1329+
// synchronous (matching the legacy rethrowCaughtError pattern).
1330+
(ReactNativeFeatureFlags.enableNativeEventTargetEventDispatching()
1331+
? describe.skip
1332+
: describe)('error handling', () => {
13251333
it('error in event handler does not break dispatch to subsequent listeners', () => {
13261334
const root = Fantom.createRoot();
13271335
const childRef = React.createRef<React.ElementRef<typeof View>>();

0 commit comments

Comments
 (0)