partysocket

A drop-in, auto-reconnecting WebSocket client with message buffering and React hooks

Library
npm
v1.3.0
1,249stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
77/100Good
Development Activity76
Maintenance88
Community60
Maturity44
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
82/100Excellent
Architecture80
Code Quality85
Innovation85
Learning Curve78

PartySocket is a WebSocket client that implements the same interface as the browser’s native WebSocket API, but adds the resilience that real applications need: automatic reconnection with configurable backoff, buffering of outgoing messages while disconnected, connection-timeout handling, and the ability to change the server URL between reconnect attempts. It began as a fork of reconnecting-websocket, updated with pending fixes, then extended by the Cloudflare/PartyKit team with first-class helpers for connecting to PartyKit and PartyServer (Durable Object) rooms by host/room/party, plus React hooks for using it idiomatically inside components.

Because it has no dependency on window, the DOM, or a particular event-emitter library, it runs unmodified in browsers, Service Workers, Node.js, React Native, Cloudflare Workers, and Deno/Bun, making it a practical choice any time an app needs one reliable WebSocket client across multiple runtimes.

What You Get

  • A WebSocket-API-compatible client class that’s a drop-in replacement for the native constructor
  • Automatic reconnection with configurable min/max delay, backoff growth factor, and retry limits
  • Outgoing message buffering while disconnected, flushed automatically once the connection reopens
  • A PartySocket subclass with host/room/party/query URL construction for PartyKit and PartyServer rooms, plus a matching PartySocket.fetch helper
  • React hooks (usePartySocket, useWebSocket) exposed via dedicated partysocket/react and partysocket/use-ws entry points
  • An event-target-polyfill sub-export for environments missing a global EventTarget/Event

Common Use Cases

  • Adding resilient, auto-reconnecting WebSocket connections to a web or React Native app without hand-rolling backoff logic
  • Connecting a frontend to Cloudflare Durable Object-backed realtime backends built with PartyKit or PartyServer
  • Sharing one WebSocket client implementation across browser, Node.js, and edge/Worker code paths

Under The Hood

Architecture - The package layers three pieces on top of a core reconnecting-WebSocket implementation. src/ws.ts (722 lines) implements ReconnectingWebSocket: it wraps a real WebSocket constructor, tracks retry/backoff state, re-emits browser-standard open/close/error/message events, and includes separate event-cloning paths for browser vs. Node/React Native runtimes (cloneEventBrowser vs cloneEventNode) because native Event construction differs across them. src/index.ts layers PartySocket on top, translating host/room/party/query options into a ws:///wss:// URL (and a matching PartySocket.fetch for one-off HTTP calls to the same room) before delegating to the base class. src/react.ts, use-socket.ts, use-handlers.ts, and use-ws.ts add a React hook layer (usePartySocket, useWebSocket) that manages the socket’s lifecycle against component mount/unmount and re-renders. Tech Stack - Written entirely in TypeScript, built with tsdown into dual ESM/CJS output with generated .d.ts/.d.cts declarations, then reformatted with oxfmt. Linting is via oxlint, tests run under vitest, and the package lives in an npm-workspaces monorepo (cloudflare/partykit) versioned with Changesets. Runtime dependencies are minimal: only its own tiny event-target-polyfill package, with react as an optional peer dependency gated by peerDependenciesMeta. Code Quality - The package ships 13 test files under src/tests/ covering reconnection behavior, error handling, React Native compatibility, module-scope isolation, React hooks, React SSR, integration flows, edge cases, performance, and the fetch helper — unusually thorough for a client library of this size. Typing is strict throughout, with any usage limited to a handful of documented event-cloning casts flagged by inline oxlint-disable comments rather than silently suppressed. API Design - The headline design decision is drop-in compatibility with the native WebSocket constructor, so existing code can adopt it with a single import swap. On top of that it exposes purpose-built subpath exports (partysocket/ws, partysocket/react, partysocket/use-ws, partysocket/event-target-polyfill) so consumers only pull in the pieces they use, plus a small, well-documented Options object (backoff timings, retry caps, buffering limits) with sensible defaults that require zero configuration to get a working reconnecting socket.

Used by 10 apps in this directory

TypeScript
49%
AGPL 3.0

BrowserOS

Browser · AI Assistants

13,248

The open-source agentic Chromium browser with native AI agents, MCP server, and visual workflow automation — your data never leaves your machine.

View details
87
Repo Health
82
Technical
69
Dependency
Built with
TypeScript49%
Rust22%
Python16%
Updated today
Java
34%
Apache 2.0

Enso

Analytics · Data Engineering · Low Code Platforms

7,437

A visual and textual programming platform for data prep and analysis where the node graph and the underlying Enso code are always perfectly in sync, built by an Alteryx co-founder on a GraalVM engine.

View details
70
Repo Health
90
Technical
62
Dependency
Built with
Java34%
TypeScript27%
Scala26%
Updated 1 weeks ago
Python
61%
Apache 2.0

marimo

Developer Tools · Data Engineering

22,393

A reactive Python notebook that eliminates hidden state, runs reproducibly, and deploys as a web app or script — stored as pure Python, built for the AI era.

View details
90
Repo Health
91
Technical
66
Dependency
Built with
Python61%
TypeScript37%
Updated today
TypeScript
98%
Other

Novu

Developer Tools

39,615

Open-source communication infrastructure that connects your products and AI agents to every channel your users live on — Inbox, Email, SMS, Push, Chat, and more.

View details
93
Repo Health
80
Technical
65
Dependency
Built with
TypeScript98%
Updated today
TypeScript
93%
Apache 2.0

Openship

Devops · Hosting Control Panel

11,078

Openship is an open-source, self-hostable deployment platform that points at a repo and builds, ships, routes, and TLS-terminates the app — driven from a desktop app, web dashboard, or CLI.

View details
82
Repo Health
85
Technical
65
Dependency
Built with
TypeScript93%
Updated today
TypeScript
92%
Apache 2.0

superset

AI Code Assistants · AI Development

13,068

Orchestrate an army of AI coding agents—Claude Code, Codex, Gemini CLI, and more—running simultaneously in isolated git worktrees from a single Electron desktop app.

View details
85
Repo Health
80
Technical
69
Dependency
Built with
TypeScript92%
Updated today
TypeScript
99%
Apache 2.0

Trigger.dev

Automation · AI Development · Developer Tools

16,062

Build and deploy fully-managed AI agents and background jobs in TypeScript — with no timeouts, durable retries, real-time observability, and elastic scaling built in.

View details
90
Repo Health
9
Technical
65
Dependency
Built with
TypeScript99%
Updated today
TypeScript
63%
Other

Typebot

Developer Tools · AI Development · No Code Platforms

10,268

Build sophisticated chatbots visually, embed them anywhere without iframes, and own your data — fully self-hostable with a modular block system and 30+ integrations.

View details
94
Repo Health
82
Technical
67
Dependency
Built with
TypeScript63%
MDX36%
Updated today
TypeScript
99%
AGPL 3.0

Webstudio

Design Tools · No Code Platforms

8,845

Open source visual development platform with complete CSS control, headless CMS integration, and full infrastructure ownership

View details
91
Repo Health
79
Technical
61
Dependency
Built with
TypeScript99%
Updated today

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search