Skip to content

fix: snapshot RN synthetic events and prevent channel echo#856

Merged
dannyhw merged 1 commit intonextfrom
dannyhw/fix/channel-synthetic-events
Feb 28, 2026
Merged

fix: snapshot RN synthetic events and prevent channel echo#856
dannyhw merged 1 commit intonextfrom
dannyhw/fix/channel-synthetic-events

Conversation

@dannyhw
Copy link
Member

@dannyhw dannyhw commented Feb 28, 2026

Summary

  • Adds patchChannelForRN which snapshots React Native synthetic event args synchronously before React recycles them back to the event pool
  • Limits WebSocket channel serialization depth to 5 to prevent circular reference crashes from deep object graphs (React fiber nodes etc.)
  • Stops the WebSocket server from echoing messages back to the sender, preventing duplicate event handling
  • Fixes polyfill.ts import from react-native-web to react-native
  • Moves setImmediate workaround from Start.tsx to polyfill.ts where it belongs

Problem

React Native still pools synthetic events (unlike React DOM 17+). When action events containing synthetic event args were serialized asynchronously by the channel transport, the events had already been returned to the pool — causing stale event warnings, serialization errors, or crashes from circular references in deep object graphs.

Additionally, the WebSocket server was broadcasting messages back to the sender, causing duplicate event processing.

Test plan

  • Run the expo example on device
  • Trigger actions (button presses, text input, etc.)
  • Verify action events display clean data in the actions panel without warnings or crashes
  • Verify actions don't double-trigger

- Add patchChannelForRN to snapshot synthetic event args before React
  recycles them, avoiding stale event pool errors in the actions panel
- Limit channel serialization depth to prevent circular reference crashes
- Stop WebSocket server from echoing messages back to the sender
- Fix polyfill.ts import to use react-native instead of react-native-web
- Move setImmediate workaround from Start.tsx to polyfill.ts
@changeset-bot
Copy link

changeset-bot bot commented Feb 28, 2026

⚠️ No Changeset found

Latest commit: 36a89d3

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@dannyhw dannyhw merged commit e918e29 into next Feb 28, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant