partysocket: new PartySocket() throws ReferenceError where there is no global crypto
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 62/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- react-native, typescript
- Lĩnh vực
- frontend, networking
Hướng nghiên cứu
Lỗi nằm ở generateUUID() trong packages/partysocket/src/index.ts (khoảng dòng 40-61), nơi crypto?.randomUUID và performance?.now tham chiếu đến các biến toàn cục có thể chưa được khai báo. Hãy bắt đầu bằng cách chạy bước tái tạo lỗi từ issue sau Reflect.deleteProperty(globalThis, "crypto"), rồi bảo vệ các truy cập đó bằng kiểm tra typeof để bộ sinh dự phòng được chạy. Hoàn thành khi new PartySocket() không có id thành công khi thiếu crypto, và bộ kiểm thử partysocket vượt qua. Tác giả đã chuẩn bị sẵn bản sửa trên một fork tại commit 5a52347, có thể dùng làm tham chiếu.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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).
- Ngôn ngữ chính
- TypeScript
- Star
- 1.3k
- Fork
- 86
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của cloudflare/partykit
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
cloudflare/partykit#443 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
cloudflare/partykit#434 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
cloudflare/partykit#430 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 69/100
cloudflare/partykit#429 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
cloudflare/partykit#428 ·
Tất cả issue của cloudflare/partykit
Issue tương tự
-
[analytics-core] getQueryParams does not decode `+` as space and truncates values containing `=`Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
amplitude/Amplitude-TypeScript#2179 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
ci good first issue severity: low
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
TMHSDigital/GH-Arcade#111 ·
-
AsnIntegerConverter.toASN coerces strings with +value, rounding integers outside safe-integer rangeĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
PeculiarVentures/asn1-schema#189 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 4 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100