PermanentUserData being overwritten

Hello, I am building a collaborative editor using prosemirror with support for tracking changes. The code is very similar to the prosemirror-versions example ( The issue is, sometimes the user shows up as “Unknown” instead of the username of the user who made the change. From what I can tell from debugging, it looks like when the document syncs with the websocket, the data for the current user gets overwritten. So if a user made a change with one clientID, then came back to the document with a new clientID, all the ‘ids’ from the user object would be deleted and replaced with the current clientID. I was actually able to replicate the issue on the demo site in FireFox by just refreshing the page a few times after making a change.

Update: I think it has to do with the setUserMapping function being called before all of the previous changes are synced. I tried waiting to call setUserMapping until the WebSocketProvider.synced is true, but it seems like the PermanentUserData hasn’t synced yet at that point. Any ideas?

Hey @blueskyler,

Thanks for noticing. Indeed, the current implementation of PermanentUserData should initialize after it connected to the server. E.g. by waiting for provider.on('synced', () => { /* initialize permanent user data and the editor */ })

Would you like to provide a PR to the demo repository?

Sure. I would also like to point out that I was able to get it working, although provider.on('synced', () => { /* initialize permanent user data and the editor */ }) did not work for me. It looked like even after the provider had synced, the document was still being updated and the previous permanent user data had not come through yet. Initializing the permanent user data after the provider had synced AND after the first update to the document fixed the issue. I’m not sure why that was, maybe it was just specific to our implementation.