ueberdosis / hocuspocus

The CRDT Yjs WebSocket backend for conflict-free real-time collaboration in your app.
https://tiptap.dev/docs/hocuspocus/introduction
MIT License
1.34k stars 128 forks source link

awareness.clientID out of sync with document.clientID #850

Open daveychu opened 3 months ago

daveychu commented 3 months ago

Description If Yjs detects that another client is already using the local clientID it will generate a new one. The awareness.clientID is not updated which leads to bugs in code where they are assumed to be the same.

An example is @tiptap/extension-collaboration-cursor which uses yCursorPlugin. In https://github.com/yjs/y-prosemirror/blob/master/src/plugins/cursor-plugin.js#L86C5-L86C54 it checks the yDoc.clientID with the clientId coming from the awareness states. With the above situation, it will incorrectly detect your own awareness changes as coming from another client and you will effectively see the collaboration cursor follow your own cursor.

Steps to reproduce the bug Steps to reproduce the behavior:

  1. Clone https://github.com/daveychu/hocuspocus/tree/client-id-out-of-sync
  2. Run npx ava tests/provider/onClientIdChanged.ts
  3. Test will fail on t.is(provider2.document.clientID, provider2.awareness.clientID)

Expected behavior Test should succeed. awareness.clientID and document.clientID are kept in sync.

dx1ded commented 2 months ago

+1, same here

janthurau commented 14 hours ago

hmm. Why do you have non-unique client IDs? Are you setting them manually?

I don't think we can get notified on a change of the client id (it happens here https://github.com/yjs/yjs/blob/main/src/utils/Transaction.js#L355), so this would probably be hard to do.