Skip to content
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

Error when moving an element from yjs #93

Open
hbcarlos opened this issue Nov 16, 2022 · 1 comment
Open

Error when moving an element from yjs #93

hbcarlos opened this issue Nov 16, 2022 · 1 comment

Comments

@hbcarlos
Copy link
Contributor

When using the new move feature from a Yjs client, If there is a Ypy client connected, the first client (the Yjs client that moved an element) receives an event undoing the move.

Everything works fine if there is not a Ypy client connected or if the client moving an element is a python client (Ypy) .
I suspect the problem comes from my PR for the move feature #83, which I guess is missing handling a moving event coming from another client.

I have been looking into the code to see how Yrs or Ypy handles the events coming from other clients but I couldn't find anything.
@Waidhoferj, @Horusiath or @dmonad do you know where should I look in the code to debug it?

Context

To reproduce the bug you can use a Yjs client like:

const doc = new Doc();
const test = doc.getArray('test');
const provider = new WebsocketProvider('ws://localhost:8888', 'rtc_yjs_test', doc);

const observe = (event) => console.log("OBSERVER:", event.changes);
test.observe(observe);

test.push([0,1,2,3,4]);
test.move(0, 2);

and a Ypy client like:

def callbackArray(event):
    print("OBSERVER:", event.delta)

doc = Y.YDoc()
test = doc.get_array('test')
idTest = test.observe(callbackArray)

ws = await connect("ws://localhost:8888/rtc_yjs_test")
WebsocketProvider(doc, ws)

and you can start a WebSocket server with:
HOST=localhost PORT=8888 npx y-websocket

When the Yjs client moves an element it receives two events, the first event is the correct move of the element:

{
  "added": {},
  "deleted": {},
  "delta": [
    { "delete": 1 },
    { "retain": 1 },
    { "insert": [0] }
  ]
}

But the second event is reverting the move:

{
  "added": { Item([0]) },
  "deleted": {},
  "delta": [
    { "insert": [0]  },
    { "retain": 1 },
    { "delete": 1}
  ]
}
@SylvainCorlay
Copy link

Ping @dmonad in case you have an idea of what the issue may be here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants