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] SSR Mode Detection #296

Merged
merged 2 commits into from
Sep 9, 2024
Merged

[Fix] SSR Mode Detection #296

merged 2 commits into from
Sep 9, 2024

Conversation

stevensJourney
Copy link
Collaborator

@stevensJourney stevensJourney commented Sep 9, 2024

Overview

This fixes an issue where manually specifying ssrMode: true in the PowerSyncDatabase constructor flags could cause unexpected syncing behaviour to occur in the browser client.

Previously the WASQLiteOpenFactory did not account for the ssrMode flag. This would create a DBAdapter based on the detected environment. Specifying ssrMode: true would result in a functional WASQLiteDBAdapter being created (on the client).

Previously the SSRStreamingSyncImplementation extended AbstractStreamingSyncImplementation which contains logic for processing sync commands from the server. Sync commands would be a no-op if the suppled DBAdapter was a placeholder SSR DBAdapter, but as described above this was not the case if ssrMode: true was specified.

The locks in SSRStreamingSyncImplementation are not exclusive, which could result in multiple clients processing sync commands into a single SQLite DB. This PR removes the ability for SSRStreamingSyncImplementation to perform any actual syncing. This implementation is just meant to be a placeholder for cases where the PowerSyncDatabase client is accidentally used or exposed on the server.

Copy link

changeset-bot bot commented Sep 9, 2024

🦋 Changeset detected

Latest commit: a1b5110

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@powersync/common Minor
@powersync/web Minor
@powersync/react-native Patch
@powersync/diagnostics-app Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@stevensJourney stevensJourney marked this pull request as ready for review September 9, 2024 08:36
@stevensJourney stevensJourney merged commit b1a76b3 into main Sep 9, 2024
5 checks passed
@stevensJourney stevensJourney deleted the fix/ssr-mode branch September 9, 2024 11:01
@guillempuche
Copy link
Contributor

I don't find this mode in the docs. What is it about?

@stevensJourney
Copy link
Collaborator Author

I don't find this mode in the docs. What is it about?

We have a TODO for adding SSR docs.

In short: Our web SDK requires web APIs. WebAPIs are not available when the server might be rending components for SSR. Using web APIs on the server typically throws exceptions for missing methods. Our web SDK is not meant to be used on the server-side, but we provide these helpers which will avoid actually performing and DB or sync operations if a developer accidentally ends up attempting to use the SDK on the server-side.

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.

3 participants