-
Notifications
You must be signed in to change notification settings - Fork 240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Anomalous behavior occurs when repeating removing and inserting between LiveLists #1371
Comments
Hi @enk0de – thanks for taking the time to write up this issue report. I've got a few follow-up questions to help investigate this issue.
Thank you! |
interface Storage {
tree: LiveObject<{
rootNodeID: string; // Tree entry
nodes: LiveMap<string, LiveObject<{ id: string, x: string, y: string, parentNodeID?: string, children?: LiveList<string> }>>;
}>;
};
|
Amazing, thanks @enk0de! I assume you're making these three writes in a single Could you maybe share what happens in one of your observed error states? For example, do only 2 of the three updates take place? Or more than those 3? Or is there a duplicate entry somewhere? Basically: what does your erroreneous state look like in the situation like your recorded video? |
Yes, We are doing those operations in one batch callback!
In recorded video, There are two spaces there. One is inside the white box shown in the video, and the other is outside the white box. The blue rectangle in the recorded video can be dragged to become a child in either of those two spaces. Therefore, the blue square should only exist in one of the two spaces. At the beginning of the video, you can see that moving the blue rectangle slowly works fine, but when you move it very quickly, it suddenly crashes. an error situation occurs where the blue square exists in both spaces. This is not a React rendering issue, there are actually two of them in the data from Liveblocks. |
hi, @nvie. I found a solution to resolve the issue. here is my original code private deleteNodeFromParent(id: string) {
const parentNode = this.getParentNode(id);
if (parentNode === undefined) {
return;
}
const children = this.getLiveNode(parentNode.id)?.get('children');
if (children === undefined) {
throw new Error('Node children not exists');
}
const index = children.indexOf(id);
children.delete(index);
} The code below fixes the problem. private deleteNodeFromParent(id: string) {
const parentNode = this.getParentNode(id);
if (parentNode === undefined) {
return;
}
const parentLiveNode = this.getLiveNode(parentNode.id);
const originalChildren = parentLiveNode?.get('children');
if (parentLiveNode === undefined) {
throw new Error('Node not exists');
}
if (originalChildren === undefined) {
throw new Error('Node children not exists');
}
parentLiveNode.set(
'children',
new LiveList(originalChildren.filter((childID) => childID !== id))
);
} i just re-create children LiveList and replace it with originalChildren LiveList. |
Ah, I see! Thanks for sharing that code example, @enk0de. This makes the problem a bit clearer to understand. To summarize, the issue you were facing before is that under some conditions the If the above is correct, I have an idea of what might explain this issue. |
To be more precise, the node is not deleted when you do |
Thanks for sharing that extra info @enk0de. Can you maybe also share if it's only the client that's affected, or does the same bug happen in a different client/window as well when it happens? Trying to bisect if this bug is scoped to the client or to the server. Thanks! |
Hi. nvie. I am still suffering the problem. have you found out why this occurs? |
Describe the bug
Anomalous behavior occurs when removing an item from a LiveList named A, inserting it back into a LiveList named B, and then reversing the action.
A and B LiveLists are properties that belong to some LiveMap.
Here's what happens
you remove an item from a LiveList named A and insert it into a LiveList named B. (When you take a snapshot, it looks like the item is deleted from A and added to B.)
remove the item you added to B from the LiveList named B again and add it to the LiveList named A. (When you take the snapshot, it should look like the item was deleted from B and added to A.)
Repeat this behavior very quickly
After a few iterations, you should see an error situation. An error is observed, such as "The item that was removed from B is still there. We say "we observe an error such as" because the error doesn't look the same every time.
To Reproduce
Steps to reproduce the behavior:
you remove an item from a LiveList named A and insert it into a LiveList named B. (When you take a snapshot, it looks like the item is deleted from A and added to B.)
remove the item you added to B from the LiveList named B again and add it to the LiveList named A. (When you take the snapshot, it should look like the item was deleted from B and added to A.)
Expected behavior
Illustrations
2024-01-03.11.19.07.mov
Environment (please complete the following information):
"@liveblocks/client": "1.8.1",
"@liveblocks/core": "1.8.1",
"@liveblocks/node": "1.8.1",
"@liveblocks/react": "1.8.1",
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: