diff --git a/.changeset/fix-configurable-connection-props.md b/.changeset/fix-configurable-connection-props.md new file mode 100644 index 00000000..476e326e --- /dev/null +++ b/.changeset/fix-configurable-connection-props.md @@ -0,0 +1,7 @@ +--- +"partyserver": patch +--- + +Add `configurable: true` to `id`, `tags`, and `socket` property descriptors in `createLazyConnection` to fix Vite HMR compatibility + +When using PartyServer with Vite's Cloudflare Workers dev mode, HMR reloads recreate the module-scoped `WeakSet` used to track wrapped sockets, while the underlying WebSocket instances survive. This caused `Object.defineProperties` to throw `TypeError: Cannot redefine property` on properties that were missing the `configurable` flag. diff --git a/packages/partyserver/CHANGELOG.md b/packages/partyserver/CHANGELOG.md index 3a943d0c..67063c88 100644 --- a/packages/partyserver/CHANGELOG.md +++ b/packages/partyserver/CHANGELOG.md @@ -292,14 +292,12 @@ ### Patch Changes - [`528adea`](https://github.com/threepointone/partyserver/commit/528adeaced6dce6e888d2f54cc75c3569bf2c277) Thanks [@threepointone](https://github.com/threepointone)! - some fixes and tweaks - - getServerByName was throwing on all requests - `Env` is now an optional arg when defining `Server` - `y-partyserver/provider` can now take an optional `prefix` arg to use a custom url to connect - `routePartyKitRequest`/`getServerByName` now accepts `jurisdiction` bonus: - - added a bunch of fixtures - added stubs for docs diff --git a/packages/partyserver/src/connection.ts b/packages/partyserver/src/connection.ts index f1e2217a..4d71fd86 100644 --- a/packages/partyserver/src/connection.ts +++ b/packages/partyserver/src/connection.ts @@ -132,17 +132,20 @@ export const createLazyConnection = ( const connection = Object.defineProperties(ws, { id: { + configurable: true, get() { return attachments.get(ws).__pk.id; } }, tags: { + configurable: true, get() { // Default to [] for connections accepted before tags were stored return attachments.get(ws).__pk.tags ?? []; } }, socket: { + configurable: true, get() { return ws; } diff --git a/packages/y-partyserver/CHANGELOG.md b/packages/y-partyserver/CHANGELOG.md index ca1a6675..5cfe345a 100644 --- a/packages/y-partyserver/CHANGELOG.md +++ b/packages/y-partyserver/CHANGELOG.md @@ -25,7 +25,6 @@ - [#341](https://github.com/cloudflare/partykit/pull/341) [`e7f4b51`](https://github.com/cloudflare/partykit/commit/e7f4b51198904273befb1d39478840c628f6e2b1) Thanks [@threepointone](https://github.com/threepointone)! - Fix Yjs hibernation support and awareness propagation **Server:** - - Replace in-memory `WSSharedDoc.conns` Map with `connection.setState()` and `getConnections()` so connection tracking survives Durable Object hibernation - Move event handler registration from `WSSharedDoc` constructor into `onStart()` to use `getConnections()` for broadcasting - Disable awareness protocol's built-in `_checkInterval` in `WSSharedDoc` constructor to prevent timers from defeating hibernation @@ -35,7 +34,6 @@ - Widen `onLoad()` return type to `Promise` to allow seeding the document from a returned YDoc **Provider:** - - Switch awareness event listener from `"update"` to `"change"` so clock-only heartbeat renewals do not produce network traffic (allows DO hibernation during idle sessions) - Disable awareness protocol's built-in `_checkInterval` on the client to stop 15-second clock renewals and 30-second peer timeout removal - Remove provider's own `_checkInterval` liveness timer (was coupled to the awareness heartbeat) @@ -370,14 +368,12 @@ ### Patch Changes - [`528adea`](https://github.com/threepointone/partyserver/commit/528adeaced6dce6e888d2f54cc75c3569bf2c277) Thanks [@threepointone](https://github.com/threepointone)! - some fixes and tweaks - - getServerByName was throwing on all requests - `Env` is now an optional arg when defining `Server` - `y-partyserver/provider` can now take an optional `prefix` arg to use a custom url to connect - `routePartyKitRequest`/`getServerByName` now accepts `jurisdiction` bonus: - - added a bunch of fixtures - added stubs for docs