How to determine two doc are from same a origin doc?

I was working on a project that allowed users to pull document data from the server to a local document. But documents from different sources should be prohibited.

Just like in Git, you cannot pull a different git into another git repository(except you merge or force pull)

But in yjs, I saw no way to do it. GUID and clientID are inconsistent between each initiation

I think you can specify the same guid of ydoc between the server and the client.

like this:

const guid = 'your guid';

const doc = new Y.Doc({ guid });
1 Like

@Himself65 I generate a globally unique deviceId client-side on app startup and persist it to localStorage. Then I use that in the WebsocketProvider room name to ensure it only syncs data that belongs to that device.

let deviceId = localStorage.getItem(deviceId)
if (!deviceId) {
  deviceId = nanoid()

new WebsocketProvider('wss://server:8080', deviceId, ydoc)
1 Like