partysocket: new PartySocket() throws ReferenceError where there is no global crypto
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 62/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- react-native, typescript
- Domain
- frontend, networking
Research direction
The bug is in generateUUID() in packages/partysocket/src/index.ts (around lines 40-61), where crypto?.randomUUID and performance?.now reference globals that may be undeclared. Start by running the repro from the issue after Reflect.deleteProperty(globalThis, "crypto"), then guard those lookups with typeof checks so the fallback generator runs. Done means new PartySocket() without an id succeeds when crypto is absent, and the partysocket test suite passes. The author has a prepared fix on a fork at commit 5a52347 that can be used as a reference.
Written by the indexing model from the issue text.
Description
generateUUID() checks crypto?.randomUUID. Optional chaining does not protect a global name that is not declared. So where there is no global crypto (for example React Native without a polyfill), new PartySocket() without an id throws ReferenceError: crypto is not defined, and the fallback generator below is never used. performance?.now has the same problem.
Repro
The packages: [email protected]. Install them with npm i [email protected].
// npm install, then: node repro.ts (Node.js 22.18 or later runs TypeScript directly)
//
// React Native (Hermes) has no global crypto unless a polyfill adds one. This removes it to get the same
// environment.
Reflect.deleteProperty(globalThis, "crypto");
console.log("typeof crypto:", typeof crypto);
const { default: PartySocket } = await import("partysocket");
try {
const socket = new PartySocket({ host: "example.com", room: "room-1", startClosed: true });
console.log("id:", socket.id);
} catch (e) {
console.log(`new PartySocket() threw: ${(e as Error).name}: ${(e as Error).message}`);
}
// The file is a module, so top-level await works.
export {};
node repro.ts (Node.js 22.18 or later runs TypeScript directly)
Actual
typeof crypto: undefined
new PartySocket() threw: ReferenceError: crypto is not defined
Expected
The fallback generator makes an id, and the socket is made.
A fix
A fix with a new test is on the branch fix/partysocket-no-global-crypto of my fork, at 5a52347. On a GitHub Actions runner, the new test fails before the change and passes after it, and the whole partysocket suite passes. This repository accepts pull requests only from collaborators, so I did not open a pull request. I can open one if you allow it, or you can take the commit.
I found this with AI assistance (Claude) during a review of WebSocket client libraries. The repro above was run with partysocket 1.3.0 on Node.js 24.22.2 on Linux (a GitHub Actions runner), and the output above is from that run. The fix was also prepared with AI assistance (Claude).
- Dominant language
- TypeScript
- Stars
- 1.3k
- Forks
- 86
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from cloudflare/partykit
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
cloudflare/partykit#443 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
cloudflare/partykit#434 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
cloudflare/partykit#430 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 69/100
cloudflare/partykit#429 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
cloudflare/partykit#428 ·
All issues in cloudflare/partykit
Similar issues
-
bug parity
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
WenyuChiou/agent-board#1489 ·
Maintainers usually reply within 1 day
-
area: bazaar bug complexity: medium
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
accensa/x402-facilitator-stellar#779 ·
Maintainers usually reply within 1 day
-
bug good first issue P4 size:S web-ui
Difficulty 2/5 Half a day Newbie friendliness 85/100
josephfung/curia#2600 ·
Maintainers usually reply within 1 day