On (re)connect the Yjs WebSocket provider sends only a sync step 1 and relies on the server to send back its own sync step 1, asking for the updates it misses. The XWiki Yjs WebSocket endpoint doesn't hold a Yjs document, only the updates it received: it replays them, followed by an empty sync step 2, but never asks the client for anything. So the changes made while disconnected, as well as the ones sent into a connection that was already lost (up to 30 seconds before the loss is detected), never reached the other editors.
Fix
The client now holds back the history replayed by the server on (re)connect, applies it in a single transaction, computes from it what the server has and sends back what the server misses: the changes made while disconnected or lost with the connection, including delete-only changes.
The client also checks, before touching its document, whether the room was replaced while it was disconnected:
if the room is empty (everyone left), the client pushes its full state and the session continues;
if someone started a new session from the saved page meanwhile, merging would duplicate the whole content, so the editor stops synchronizing (it stays disconnected), keeps the local changes and shows a warning on the realtime toolbar explaining that the changes are not shared anymore.
The realtime toolbar can now display warnings (an icon showing the message in a popover), through a generic API that other realtime editors can use.
Limitations / follow-ups
When the session was replaced, the local changes are kept but not merged into the new session: the user has to copy them and reload the editor. Reconciling them automatically, or avoiding the problem by persisting the Yjs document of each page (so that a new session continues the previous one), is left for follow-up issues.
A client that edited since its last synchronization re-sends its delete set (idempotent, usually small) each time it reconnects.
Tests
New unit tests running the real Yjs WebSocket provider against a fake room mimicking the XWiki endpoint (offline insert, offline delete, update lost with the connection, reconnect without changes, room discarded, room replaced), plus tests for the toolbar warnings.
BlockNote CollaborationIT passes (11/11).
This message was sent by Atlassian Jira (v9.3.0#930000-sha1:287aeb6)
If image attachments aren't displayed, see this article.