npm / centrifuge
centrifuge
What changed in centrifuge 4 to 5, from its official release notes, upgrade guides and advisories. Sources checked 2026-11-30.
12 breaking4 new APIs and options8 behavior and defaults1 tooling20 fixes and other
See which of these apply to your code, ranked, in your agent:
npx @unstale/cli initcentrifuge 543 changes
Breaking changes 12
Configuration errors such as no supported transport, no WebSocket implementation, or an http(s) endpoint string are thrown from connect() rather than leaving the client connecting or retrying.
Calls made while disconnected now fail instead of waiting for a connection until their timeout.
An exception in a client or subscription event handler disconnects the client without reconnecting, reports an unhandled rejection, and leaves the client consistent.
Other exceptions while handling a message stop the client with a visible disconnect instead of silently stopping processing while connected.
The subscription is removed before its unsubscribed event, allowing a handler to create a replacement on the same channel; removing an old object no longer removes the replacement.
Keys whose track fails permanently are untracked and each receives a removal update, rather than remaining tracked and replaying on every reconnect.
Shared poll update versions are numbers over the protobuf protocol rather than Long objects.
Protocol offsets are numbers rather than Long objects; positions stored by earlier versions and passed through since are converted, while offsets above 2^53 lose exactness.
Calling subscribe() on a removed subscription now throws instead of creating an untracked server subscription whose publications are dropped.
A static subscription token receiving error 109 ends unsubscribed with unauthorized code 1 and a configuration error instead of clearing the token and retrying without one.
Protobuf clients are imported as a named
Centrifugeexport instead of a default import.The
protocoloption was removed from the Centrifuge instance config object.
New APIs and options 4
The client listens for page lifecycle events on pageEventTarget, defaulting to globalThis where supported; use a target that does not fire these events to opt out of back/forward cache handling.
A new getState callback is available for stream subscriptions.
Map subscriptions are added as a subscription type.
Shared Poll subscriptions are added as a subscription type.
Behavior and default changes 7
On persisted pagehide, the client closes its transport and moves to connecting; on persisted pageshow, it reconnects and recovers subscriptions.
Closing a transport aborts pending emulation requests; network failures and 404/5xx responses close the transport so the client reconnects without waiting for the command timeout.
The zero-delay first round over a transport list no longer counts towards reconnect backoff.
Pushes are delivered to a server-side subscription when a client-side subscription object for the same channel is not subscribed.
A new signature replaces stored signatures whose keys it fully covers.
Undecodable data closes the transport, after which the client reconnects using its usual backoff and transport fallback.
An imported Protobuf client automatically uses the Protobuf protocol, so callers no longer need to specify it in the constructor.
Tooling 1
The library is built with Rollup and supports both ESM and CommonJS, helping users integrate it with existing toolchains.
Fixes and other changes 19
Stream transport close is handled after received data is dispatched, so a disconnect push written immediately before close is applied.
Late call, no-ping, and connect timers allow already-received replies, pings, or open events to be processed first.
A channel the server does not recover no longer reports a failed recovery when positioning is enabled and a subscription has a position.
Without getToken, setToken() after a token-expired error clears the pending refresh so the next connect() uses the new token; with getToken, the next attempt still calls it.
track() calls made while a subscribe completes, such as from a subscribed handler, are sent with the replay that follows.
Updates with a version not newer than the held version for a key are dropped, preventing duplicate delivery and older updates replacing newer ones.
Without getToken, disconnect and unsubscribe state invalidation keeps the static token, allowing reconnect or resubscribe with it.
Fixes UTF-8 corruption when a character spans two stream chunks.
Byte counts for non-ASCII JSON payloads are corrected, so delta stats report accurate sizes.
Pending publish-debounce timers are canceled on reconnect.
The server-side subscription recovery position is reset when state is invalidated.
Prevents a crash when the final WebTransport read chunk has no value.
Fixes an out-of-bounds transport index during initialization.
Sets the _triedAllTransports flag when unsupported transports are skipped.
Fixes a localStorage access error in Safari private browsing mode.
Fixes edge cases in channel compaction.
Aligns state invalidation across both disconnect paths and unrecoverable resubscribe, with named codes.
Fixes a bug with instanceof checks for Array.
Fixes a TypeError caused by localStorage.getItem not being a function on NodeJS 25.
centrifuge 42 changes
Behavior and default changes 1
Returning an empty string is now valid and does not disconnect the client; throw UnauthorizedError() from getToken to disconnect it.
Fixes and other changes 1
The SDK adds setToken back, allowing the token to be reset to empty when a user logs out.