partysocket: new PartySocket() throws ReferenceError where there is no global crypto
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 62/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- react-native, typescript
- 領域
- frontend, networking
調査の方向性
バグは packages/partysocket/src/index.ts の generateUUID()(40〜61行目付近)にあります。ここでは crypto?.randomUUID と performance?.now が、宣言されていない可能性のあるグローバルを参照しています。まず issue の再現手順を Reflect.deleteProperty(globalThis, "crypto") の後で実行し、次にこれらの参照を typeof チェックで保護して、フォールバックの生成処理が動くようにしてください。crypto が存在しない状態で id なしの new PartySocket() が成功し、partysocket のテストスイートが通れば完了です。作者は fork のコミット 5a52347 に修正を用意しているので、参考にできます。
索引モデルが issue の本文から書いたものです。
説明
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).
- 主要言語
- TypeScript
- スター
- 1.3k
- フォーク
- 86
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
cloudflare/partykit のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
cloudflare/partykit#443 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
cloudflare/partykit#434 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
cloudflare/partykit#430 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 69/100
cloudflare/partykit#429 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
cloudflare/partykit#428 ·
cloudflare/partykit の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
steelbrain/node-ssh#487 ·
-
cli: `execCargoMetadata` decodes stdout per chunk, corrupting non-ASCII paths across pipe boundariesオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
難易度 1/5 1時間未満 初心者へのやさしさ 62/100
lingdojo/kana-dojo#34127 · コメント 1 件 · リアクション 5 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 68/100
osmlab/name-suggestion-index#13104 ·
メンテナーはふだん 1 日以内に返信