ls1intum / Apollon

UML Modeling Editor written in React
https://apollon-library.readthedocs.io
MIT License
61 stars 21 forks source link

Bugfix/colliding patches #344

Closed loreanvictor closed 4 months ago

loreanvictor commented 4 months ago

This PR is stacked on top of #343

Checklist

Motivation and Context

In realtime collaboration, sometimes patches without any apparent conflict will result in cancellation of local changes on a client. This PR fixes this issue.

Description

In realtime collaboration, one client might be in the middle of making some changes while a patch to the diagram state is received from some remote. Upon receiving a patch, the patcher will apply the received patch to its own snapshot of the state, and then the reducer will set the local state to that patched state. If unsaved local changes are not synced with patcher's snapshot, the changes will be reverted.

This particularly happens a lot with continuous syncing (using .subscribeToAllModelChangePatches() method for realtime collaboration), as a stream of incoming patches will repeatedly cancel local changes the user is trying to do simultaneously. Note that the patcher's snapshot is intentionally kept behind local state to ensure small continuous changes don't result in patches not being sent enough (the patcher always sends the diffs with the last discrete changes).

This PR adds the option to update patcher's snapshot upon patching, and ensures the reducer will update the patcher's snapshot before merging the state with incoming patches. This solution will keep patcher's snapshot behind the local state to ensure sufficient emission of necessary patches, while resolving the issue at hand.

Steps for Testing

  1. Clone this branch,
  2. Clone Apollon_standalone and link the cloned Apollon code,
  3. On Apollon_standalone, use continuous sync by ensuring .subscribeToAllModelChangePatches() method is used here,
  4. Run two clients (ideally separate machines) working on the same diagram. The two clients should be able to smoothly change things at the same time without getting stuck.

Test Coverage

File Branch Line
components/store/model-store.tsx 100% 100%
services/patcher/patcher.ts 96.77% 100%
services/patcher/patcher-reducer.ts 90.9% 100%

Screenshots

ScreenRecording2024-02-19at08 52 32-ezgif com-video-to-gif-converter