In the Liveblocks 0.19 release, we’re adding support for Zustand v4 to
@liveblocks/zustand
. Zustand v4 brings greatly improved TypeScript types to
its APIs, enabling us to enhance the quality of our types, bringing it in line
with our React package.
Let’s take a look!
To update @liveblocks/react
to 0.19, run the following command using your
preferred package manager:
useOther
now requires a
selector
function argument. You will need to replace instances of useOther
that do not
use a selector in your codebase.
We’ve added support to prevent the stale props/zombie child scenario. To avoid
this issue, we enforce passing the unstable_batchedUpdates
prop to
RoomProvider
.
For additional context, see the troubleshooting guide
To update @liveblocks/redux
to 0.19, run the following command using your
preferred package manager:
The main export has been renamed, so you will need to update your imports and use of the enhancer:
When calling state.liveblocks.enterRoom()
, you should not pass an explicit
initial state. It will use the state in your Redux store, for consistency and
ease of use. To migrate, make the following code changes:
In 0.19 we added support for Zustand v4 (specifically v4.1.3 or higher) and will no longer support Zustand v4.1.2 or lower. This is because Zustand v4.1.3 brings greatly improved TypeScript types to its APIs, and consequently, we can improve our internal types. To migrate, make the following code changes:
To update @liveblocks/zustand
to 0.19, run the following command using your
preferred package manager:
To be clear:
liveblocks
middleware call,
and onto the create
call.MyState
type in a WithLiveblocks<...>
wrapper. This will
make sure the injected liveblocks
property on your Zustand state will be
correctly typed.()
wrapper, needed by Zustand v4
now:
state.liveblocks.enterRoom()
: it no longer
takes an explicit initial state. Instead, it’s automatically be populated from
your Zustand state.This release brings several changes to @liveblocks/react
, which improve
rendering performance and stability. Additionally, we have refactored our
internal packages to increase code sharing. You can review the
release notes for more
details.
We added a new property shouldInitiallyConnect
to RoomProvider
, which lets
you control whether or not the room connects to Liveblock servers. By default,
it will check the typeof window
to determine if it should connect. When using
SSR, you can set it to false
to prevent the room from connecting to Liveblocks
servers.
We restructured our internal packages to increase code sharing. You may notice a
new dependency in your dependency tree: @liveblocks/core
. It contains private
APIs that aren’t intended for direct consumption.
Similar to the shouldInitiallyConnect
prop in
@liveblocks/react
, we added a shouldInitiallyConnect
option to
client.enter
. The default value is true
. You may want to set it to false
when using SSR, or if you would prefer to establish the WebSocket connection
later.
All packages now provide an isReadOnly
flag on user instances. It is available
by calling getSelf()
and getOthers
. isReadOnly
is true when storage is
read-only, as well as when a user has read
permission to the room
and
write
permission to presence
.
You can learn more about room permissions under authentication.
That’s it!
If you run into issues with these new patterns and you need help, please let us know by email or by joining our Discord community! We’re here to help!