Migrate from JavaScript SDK 10.x.x to 11.0.0
This guide upgrades the PubNub JavaScript SDK from 10.x.x to 11.0.0. Version 11.0.0 changes the enableEventEngine and restore defaults to true and removes the upper bounds on retry policy values. These changes affect an app only if it omits enableEventEngine or restore from the client configuration, or relies on retry policy validation errors. An app that sets these options explicitly keeps its behavior.
Upgrade the SDK
Upgrade the pubnub package to 11.0.0 or later. The latest version is 13.1.3.
Update status listeners for the new subscription workflow
With enableEventEngine at its new default of true, the client uses the new subscribe and presence workflows and emits the updated set of status events. Messages, presence events, and all other APIs work as before.
If your status listener treats PNConnectedCategory as "the subscribed channels changed", handle PNSubscriptionChangedCategory instead. The client now emits PNConnectedCategory only when the subscription starts. See Migrating to the new subscription loop for the full comparison and a listener example.
These settings also change when enableEventEngine is true:
maintainPresenceStatetakes effect, so the client re-sends the presence state that you set on every subscribe call.autoNetworkDetectionis ignored.- If you set no
retryConfiguration, the client applies a default retry policy to subscribe requests.
For the values and exact behavior, see Configuration.
Keep the legacy subscription manager (optional)
The legacy subscription manager is the 10.x.x default. If your app depends on it, set enableEventEngine: false.
1
Choose the network-loss behavior
restore now defaults to true in browsers. It requires listenToBrowserNetworkEvents, which also defaults to true. When the network drops, the client moves to the disconnected state without sending leave events. It keeps the current timetoken and channel list so it can catch up on missed messages when connectivity returns.
If your app depends on the 10.x.x behavior, where the client resets the timetoken and channel list on network loss, set restore: false. Then subscribe again after the client emits PNNetworkUpCategory.
1
Review retry policy values
The SDK no longer enforces upper bounds in validate() on LinearRetryPolicy and ExponentialRetryPolicy. In 10.x.x, maximumRetry above 10 for the linear policy, maximumRetry above 6 for the exponential policy, and maximumDelay above 150 seconds for the exponential policy threw a validation error. Version 11.0.0 accepts them.
If your app relied on those errors to catch misconfigurations, check that each maximumRetry and maximumDelay value suits your app.
Set retry limits explicitly
The JavaScript SDK doesn't enforce upper bounds on maximumRetry or maximumDelay.
Without limits, misconfigured policies may cause excess network traffic, battery drain, or usage spikes. Always choose values suited to your app.
Related tasks
- Monitor and respond to connection status changes. React to the status events that the client emits.
- Reconnection policies. Choose a linear or exponential retry policy.
- Configuration. Look up
enableEventEngine,restore, andretryConfiguration. - JavaScript SDK 12.0.0 migration guide. Continue from 11.x.x to 12.0.0.