Skip to content

Type, document, and refactor Sync, port tests to Mocha #1331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 47 commits into
base: master
Choose a base branch
from

Conversation

raucao
Copy link
Member

@raucao raucao commented Jun 8, 2025

Includes some small other improvements. However, this PR is mostly about properly typing and documenting sync, as well as making the functions more readable by using async/await in many places.

Noteworthy additional changes:

  • Adds a new event called "sync-started", when a periodic/background sync has started (but not when outgoing changes are synced immediately).
  • Emit conflict change events asynchronously, so app developers don't have to handle them in a special way, improve conflict event docs
  • Do not emit conflict events for nodes that were deleted both locally and remotely (d04f334)
  • Fix remote deletes not handled properly when folder has local changes (098962d)
  • For more, see referenced issues below

refs #1251 (where I added sub-issues that are all easier to tackle with these changes)
refs #1270
closes #1173
closes #839
fixes #1335
fixes #1204

P.S.: I rebased the branch as much as possible before opening the PR. But there are too many conflicts when trying to consolidate the rest even more.

@raucao
Copy link
Member Author

raucao commented Jun 16, 2025

Added a rather useful change for conflict events: handling them in apps doesn't require manually using setTimeout or similar anymore.

Also, My Favorite Drinks now has support for updating drinks and it will automatically handle conflicts:

https://github.com/remotestorage/myfavoritedrinks/blob/master/app.js#L50-L59

https://myfavoritedrinks.remotestorage.io

@raucao raucao force-pushed the feature/1251-sync branch from 012e75d to 91bf93d Compare June 16, 2025 09:36
This way, apps can use these the same way as they can use other change
events.
raucao added 3 commits June 18, 2025 12:29
This can cause documents to either not be deleted at all when they
should be, but at the least for the parent folder's `local` itemsMap to
become inconsistent and potentially persist forever, because it can
never be the same as the remote itemsMap again (which is the criterium
for removing it).
No changes can be lost when documents are deleted on both ends
@raucao raucao force-pushed the feature/1251-sync branch from 11ad749 to d04f334 Compare June 18, 2025 10:43
@raucao
Copy link
Member Author

raucao commented Jun 18, 2025

I was able to address almost all of the sub-issues of #1251 in this PR now. The couple of issues that are left open should be addressed in separate PRs after this one is merged.

It doesn't matter if a client received `sync-started` or not. When there
are no more tasks to run after any task has finished successfully, the
sync is done.

Also removes a superfluous second log statement for when sync is done.
@DougReeder
Copy link
Contributor

The tests pass on my dev machine, the tests appear to cover new/changed functionality, and there's no code smell. But I'm not familiar enough with the syncing code sign off on this.

@raucao
Copy link
Member Author

raucao commented Jul 16, 2025

@galfert Any chance you could have a look at this soon?

@raucao raucao mentioned this pull request Jul 25, 2025
@raucao
Copy link
Member Author

raucao commented Jul 27, 2025

We'll have to merge this soon, because I cannot add any more PRs against this one. It's already too large.

@rosano
Copy link
Contributor

rosano commented Jul 28, 2025

We'll have to merge this soon, because I cannot add any more PRs against this one. It's already too large.

Since it's been about two months, I would ask or tag other core people individually and wait a day or two for any commitment to review, else merge.

@raucao
Copy link
Member Author

raucao commented Jul 29, 2025

/cc @michielbdejong @silverbucket

@silverbucket silverbucket self-requested a review July 29, 2025 08:18
@raucao raucao requested review from galfert and michielbdejong and removed request for a team July 29, 2025 08:30
Copy link
Member

@silverbucket silverbucket left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM, tests are all passing 👍

@rosano
Copy link
Contributor

rosano commented Jul 29, 2025

I tried CRUD on this rough build of hyperdraft and it seemed to sync fine between 2 private windows https://test-hyperdraft.remit.rosano.ca/en/write

@raucao
Copy link
Member Author

raucao commented Jul 29, 2025

Bonus: if your app uses change events with origin window, it should even work between browser tabs in the same browser session now (and instantly).

@rosano
Copy link
Contributor

rosano commented Jul 29, 2025

Bonus: if your app uses change events with origin window, it should even work between browser tabs in the same browser session now (and instantly).

Looking forward to implementing that in future apps, and maybe documenting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
5 participants