hocuspocus icon indicating copy to clipboard operation
hocuspocus copied to clipboard

awareness.clientID out of sync with document.clientID

Open daveychu opened this issue 1 year ago • 1 comments

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.

daveychu avatar Aug 20 '24 17:08 daveychu

+1, same here

vovados1 avatar Sep 05 '24 07:09 vovados1

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.

janthurau avatar Nov 22 '24 13:11 janthurau