Git Product home page Git Product logo

Comments (5)

nvie avatar nvie commented on June 15, 2024 6

I looked into this a bit deeper today, and have found a sequence of operations that may cause history loss. Maybe this is what's happening for you here? It could happen if multiple calls to .pause() would get made before .resume() is called. That bug is now fixed in 1.8.1.

@enk0de Would you mind upgrading to this version and see if this fixes you problem?

from liveblocks.

enk0de avatar enk0de commented on June 15, 2024 1

hi! i'm really impressed with your amazing support and willingness to solve problems. I don't think I've ever seen such a quick response and enthusiastic willingness to solve problems in the GitHub community.

Thank you so much for your quick response and subsequent release with the bug fix. I'm looking forward to trying out your 1.8.1 release!

from liveblocks.

nvie avatar nvie commented on June 15, 2024

Hi @enk0de β€” thanks for opening this bug report. Just to make sure we correctly understand you... what does your expected vs actual undo stack look like in this example?

Also, have your tried upgrading to the latest version of Liveblocks? There have been a few small updates to the undo stack internals since 0.17.

from liveblocks.

enk0de avatar enk0de commented on June 15, 2024

Hi @nvie. first of all, i apologize for making confusion due to lack of explanation.

Before further explanation, I would like to inform you of changes to the issue contents. The version of @liveblocks/client that i am using is 1.7.1 not 0.17.1.

I am suffering 2 issues that i found.

  1. History disappears when i use history.pause/resume in batch callback
  2. History disappears intermittently

[1. History disappears when i use history.pause/resume in batch callback]

The code described below is like pseudocode, with details omitted to help understand the context.

Let's say we have two functions.

First one is

class CanvasService {
  private liveNodes: LiveMap<string, LiveNode>;
  
  ...

  public addNodes(
    nodes: Node[]
  ) {
    **this.room.history.pause();**
    nodes.forEach((node) => this.liveNodes.set(node.id, node));
    **this.room.history.resume();**
  }
}

Second one is

function addNodesAndDoSomething() {
  liveblocksService.batch(() => {
    canvasService.addNodes([~~~~]);
    // do something
  })
}

when i call addNodesAndDoSomething(), All history accumulated before calling this function will be lost.

[2. History disappears intermittently]

I didn't know exactly why or in what cases it happens. But I found a way to reproduce it to some extent.

we are managing selectedNodeIDs in LiveBlocks Presence. so, when user select a node, application will update presence with updatePresence() liveblocks api.

In the following way.

updatePresence({
  selectedNodeIDs
}, {
  addToHistory: true
});

and also we pass an object called { addToHistory: true } as the second argument to record selectedNodeIDs as history so that undo and redo can be performed.

At this time, if i call updatePresence({selectedNodeIDs}, {addToHistory:true}) twice with the exact same first argument value (selectedNodeIDs), suddenly history disappears. and undo/redo doesn't work.

from liveblocks.

nvie avatar nvie commented on June 15, 2024

All history accumulated before calling this function will be lost

Do you mean that the undo stack itself will be empty after calling addNodesAndDoSomething β€” i.e. canUndo becomes false? That should definitely not happen, and I would consider that a bug for sure.

However, if I try the following on an arbitrary room:

room.batch(() => {
  room.history.pause();
  /* mutate room here arbitrarily */
  room.history.resume();
});

…it seems to work as expected, and I don't see the history disappear. Can you share a bit more context that may be relevant for how your application is structured? Is there outer context maybe that also uses batches or that pauses history before reaching this snippet?

Regarding your second problem:

At this time, if i call updatePresence({selectedNodeIDs}, {addToHistory:true}) twice with the exact same first argument value (selectedNodeIDs), suddenly history disappears. and undo/redo doesn't work.

That's certainly not right either! I could not replicate this behavior locally either, no matter what I tried. Is this code running in a specific batch context, or after calling .pause()? Would love to see an exact replication, any help in the form of a sequence of function calls that triggers this case would help debug this.

from liveblocks.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.