plane icon indicating copy to clipboard operation
plane copied to clipboard

[WEB-1322] dev: conflict free pages collaboration

Open aaryan610 opened this issue 9 months ago • 0 comments

What's new?

Pages now support a conflict-free data merging along with OFFLINE editing.

Implementation

Added yjs to efficiently manage conflicts in pages. When on a page, new data gets fetched every 10 seconds and if there's anything new, the changes get merged without any conflicts with the local changes, removing the risk of data loss.

Apart from this, along with the auto-save logic, users can now hit Ctrl/Cmd + S or click on the Save changes button to save their data.

Custom provider

Created a custom provider- CollaborationProvider to handle updates on the page

export interface CompleteCollaboratorProviderConfiguration {
  /**
   * The identifier/name of your document
   */
  name: string;
  /**
   * The actual Y.js document
   */
  document: Y.Doc;
  /**
   * onChange callback
   */
  onChange: (updates: Uint8Array) => void;
}
  1. name- Uniquely identifier for each page.
  2. document- Actual YDoc to read from and write on.
  3. onChange- Callback to handle updates.

The main function of the provider is to handle updates on the document. All the updates performed in a time window of 2 seconds are merged using mergeUpdates from yjs and then the onChange callback is triggered using this merge updates.

IndexedDB for offline support

Added y-indexeddb to handle changes made when the client is offline, all of the updates made(online and offline) are stored in the indexedDB and on reconnecting, these changes are applied to the YDoc. These changes are then listened by the CollaborationProvider which triggers the onChange callback with these updates.

Plane issue: WEB-1322

aaryan610 avatar May 15 '24 12:05 aaryan610