Skip to content

Conversation

@amondnet
Copy link

@amondnet amondnet commented Nov 26, 2025

Summary

Fixes #257

React Native/Expo users experience TypeError: Failed to execute 'dispatchEvent' on 'EventTarget': parameter 1 is not of type 'Event' when using partysocket.

Root Cause

The environment detection logic incorrectly identifies React Native as a browser environment because:

  • React Native has both process and document polyfilled
  • But lacks process.versions.node
  • This caused isNode = false, selecting browser-style event cloning
  • Browser-style cloning produces events that fail instanceof Event checks in event-target-polyfill

Solution

Added explicit React Native environment detection using the standard navigator.product === "ReactNative" check:

const isReactNative =
  typeof navigator !== "undefined" && navigator.product === "ReactNative";

const cloneEvent = isNode || isReactNative ? cloneEventNode : cloneEventBrowser;

Changes

  • packages/partysocket/src/ws.ts - Added React Native environment detection
  • packages/partysocket/src/tests/react-native.test.ts - Added test coverage

Test Plan

  • All existing tests pass (45 tests)
  • Added 5 new tests for React Native environment detection
  • Linting passes (Biome, Prettier)

…Event

React Native/Expo environments have both `process` and `document` polyfilled,
but not `process.versions.node`. This caused the library to incorrectly use
browser-style event cloning, which produces events that fail `instanceof Event`
checks in event-target-polyfill.

This fix adds explicit React Native detection using the standard
`navigator.product === "ReactNative"` check, and uses Node-style event
cloning which creates proper Event instances.

Fixes cloudflare#257
@changeset-bot
Copy link

changeset-bot bot commented Nov 26, 2025

🦋 Changeset detected

Latest commit: f5851a9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
partysocket Patch

Not sure what this means? Click here to learn what changesets are.

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

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.

partysocket: TypeError: Failed to execute 'dispatchEvent' on 'EventTarget': parameter 1 is not of type 'Event'.

1 participant