The latest content is covered in multi-person collaborative scenarios

@Eric Eric
Fri, 12 Dec 2025 05:29:03 +0000

I’m using hocuspocus, yjs, and prosemirror to build my collaborative online document library. I’ve encountered a strange phenomenon: when user A and user B are simultaneously editing the same document, user A stops editing to do other things and then goes home, putting their browser to sleep. User B continues editing. The next morning, user B finds that their newly written content has been overwritten by user A’s old document content.

After investigating this issue, I discovered that once the browser goes to sleep, it no longer receives or executes user B’s new content. User A’s document remains the old one. When user A turns on their computer the next day, the startSync method in hocuspocus is executed first, and then the content is overwritten.

I checked hocuspocus-server and found that if applyAwarenessUpdate doesn’t pass an update request, it won’t be overwritten.

applyAwarenessUpdate method

if (added.length > 0 || updated.length > 0 || removed.length > 0) {
    awareness.emit('update', [
      {
        added,
        // updated passing an empty array solves this problem
        // but the user's cursor will no longer update.
        updated,
        removed,
      },
      origin,
    ]);
  }

I don’t understand why. Has anyone encountered the same problem?