Skip to content
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

[Fix] Shared sync #71

Merged
merged 3 commits into from
Feb 20, 2024
Merged

[Fix] Shared sync #71

merged 3 commits into from
Feb 20, 2024

Conversation

stevensJourney
Copy link
Collaborator

Description

It was recently discovered in the YJS NextJS demo app that watched uploads would take long to trigger if multiple Powersync instances were created for the same DB. This was due to the sync status not being correctly shared between the (multiple) instances. The second instance would not trigger uploads since it did not know a connection to the PowerSync instance was established by the first instance.

This same issue would manifest itself in regular apps (with a single instance per tab). Sync statuses between multiple tabs would not be shared. Subsequently opened tabs would remain in connected: false mode.

The root cause of this issue was that the SharedSyncImplementation.worker.ts shared worker failed to run and share syncing information between tabs and instances. The worker thew an exception when trying to access the window object in the global worker scope. The window object is not directly used in this worker codebase, but it is tested against in the object-hash library. The issue seems to be cause from bumping the NextJS version to 14.1.0. This issue mentioned that versions after 14.0.0 can incorrectly compile checks on window objects. This issue seems to be resolved here vercel/next.js@cfedc52. For better compatibility the object-hash library is removed since it's not actually needed. This fixes the shared worker from trying to access window.

Testing

Functionality was confirmed for the YJS demo app and React Native Todolist apps.

Screen.Recording.2024-02-19.at.15.56.53.mp4

@stevensJourney stevensJourney marked this pull request as ready for review February 19, 2024 14:56
@stevensJourney stevensJourney merged commit 69592d0 into main Feb 20, 2024
1 check passed
@stevensJourney stevensJourney deleted the fix/shared-sync branch February 20, 2024 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants