yjs / y-protocols

Yjs encoding protocols
MIT License
106 stars 39 forks source link

When yjs clientId changed by the yjs library, the awareness crash #19

Open ulion opened 2 years ago

ulion commented 2 years ago

I encountered crash here: TypeError: Cannot read properties of undefined (reading 'clock') https://github.com/yjs/y-protocols/blob/e7da0a137d386ae2d2db63aed9794028ce1328ef/awareness.js#L201

seems right after this happened: https://github.com/yjs/yjs/blob/9f1548204ac8a5960c3112f96de4c962bbd264e8/src/utils/Transaction.js#L334

the yjs library may change clientId, but the awareness is not ready for that.

MaxNoetzold commented 1 year ago

I also encounter this error regularly. I tried this simple solution:

const clientMeta= /** @type {MetaClientState} */ (awareness.meta.get(clientID))
if (!clientMeta) continue;
const clock = clientMeta.clock;

But it actually doesnt really solve the problem. The error itself is solved, but it leads to the problem that the client is out of sync afterwards.

nightgrey commented 1 year ago

Also have this issue in regards to https://github.com/facebook/lexical and yjs.

I'm not entirely sure about the internals of YJS; why does the client ID change happen in the first place?

hiramhuang commented 1 year ago

Same here