liveblocks / liveblocks

Liveblocks is the platform for adding collaborative editing, comments, and notifications into your application.
https://liveblocks.io
Apache License 2.0
3.51k stars 281 forks source link

[BUG]: Liveblocks is temporarily duplicating frequently changed array values #1051

Open noahbaron91 opened 1 year ago

noahbaron91 commented 1 year ago

Describe the bug

Frequently changing array values are being temporarily duplicated by liveblocks when using the Zustand connector.

I prepared a simple example that displays this issue, similar to the project I'm working on: https://github.com/noahbaron91/liveblocks-array-bug / https://stackblitz.com/github/noahbaron91/liveblocks-array-bug

In this example, a layer is moving in and out of another layer at a quick rate. Liveblocks will randomly duplicate the stored ids when updated at a fast rate (approx 50ms per action).

I have noticed that it quickly recovers, but this short duplication is causing issues for me.

Steps to reproduce the behavior:

  1. Go to https://stackblitz.com/github/noahbaron91/liveblocks-array-bug or clone https://github.com/noahbaron91/liveblocks-array-bug
  2. Create a .env file with a VITE_LIVEBLOCKS_PUBLIC_API_KEY value or fill in the public API key directly
  3. Run yarn install and yarn run dev
  4. Run the app. The app throws an error when there are duplicate child ids.
  5. You can disable liveblocks from storing the layers property to confirm that the app is working properly

Expected behavior

Liveblocks should not duplicate array values and should instead stay consistent with the Zustand storage

Illustrations

https://github.com/liveblocks/liveblocks/assets/32229274/446107b5-7317-4d00-ab6d-2d5e85025bdb

Environment (please complete the following information):

nvie commented 1 year ago

Hi @noahbaron91 - thank you for reporting this bug. Please excuse our delay in response here ā€“ part of our support team was out for holidays.

This looks like an instance of a bug we already have on our radar (see #628 and #731). We have a potential fix for this, currently in draft in #1002, which still needs to be unit tested properly, and verified for production-readiness. We'll keep you posted on when we have an official release for this bug fix.

If you're willing and able to help us verify that this fixes your issue in the mean time, you could:

npm install @liveblocks/client@1.2.2-test5 @liveblocks/zustand@1.2.2-test5

Does that fix your issue as expected? Thanks in advance! šŸ™

noahbaron91 commented 1 year ago

No problem @nvie, Unfortunately, using version 1.2.2-test5 does not resolve the issue for me. I'm still experiencing the same duplication of list elements when using that version

nvie commented 1 year ago

That's unfortunate, we'll have to keep digging a bit more then. Thanks for trying it out and letting us know, @noahbaron91.