-
Notifications
You must be signed in to change notification settings - Fork 60
[Fix] OPFS Multitab issue #786
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
base: main
Are you sure you want to change the base?
Changes from all commits
e61059a
a12145f
b4f5c1b
355e396
c6ba9f6
9730337
58f412b
8721538
feca863
b0dd596
de7804f
c08e664
aedc855
62b04de
0fc0d73
91db686
deaf83c
3780223
8f95e10
1e880d6
da53396
28472e3
11b7a36
7e7ec91
1e9fa3f
07231cb
cbfb683
f881992
ffe5abe
58d9194
1ef44a3
d73d9d2
a1fd0bb
445ec69
6630097
bbfdcf7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@powersync/web': patch | ||
| --- | ||
|
|
||
| No longer awaiting when aborting connection on tab closure. Fixes some edge cases where multiple tabs with OPFS/Safari can cause deadlocks. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@powersync/common': minor | ||
| --- | ||
|
|
||
| Serializing upload and download errors for SyncStatus events. Small changes to how delay values are passed to the sync implementation internally. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| import { CoreStreamSubscription } from '../../client/sync/stream/core-instruction.js'; | ||
| import { SyncClientImplementation } from '../../client/sync/stream/AbstractStreamingSyncImplementation.js'; | ||
| import { InternalProgressInformation, ProgressWithOperations, SyncProgress } from './SyncProgress.js'; | ||
| import { CoreStreamSubscription } from '../../client/sync/stream/core-instruction.js'; | ||
| import { SyncStreamDescription, SyncSubscriptionDescription } from '../../client/sync/sync-streams.js'; | ||
| import { InternalProgressInformation, ProgressWithOperations, SyncProgress } from './SyncProgress.js'; | ||
|
|
||
| export type SyncDataFlowStatus = Partial<{ | ||
| downloading: boolean; | ||
|
|
@@ -250,13 +250,28 @@ export class SyncStatus { | |
| return { | ||
| connected: this.connected, | ||
| connecting: this.connecting, | ||
| dataFlow: this.dataFlowStatus, | ||
| dataFlow: { | ||
| ...this.dataFlowStatus, | ||
| uploadError: this.serializeError(this.dataFlowStatus.uploadError), | ||
| downloadError: this.serializeError(this.dataFlowStatus.downloadError) | ||
| }, | ||
| lastSyncedAt: this.lastSyncedAt, | ||
| hasSynced: this.hasSynced, | ||
| priorityStatusEntries: this.priorityStatusEntries | ||
| }; | ||
| } | ||
|
|
||
| protected serializeError(error?: Error) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not all errors are serialisable over a MessagePort. E.g. some |
||
| if (typeof error == 'undefined') { | ||
| return undefined; | ||
| } | ||
| return { | ||
| name: error.name, | ||
| message: error.message, | ||
| stack: error.stack | ||
| }; | ||
| } | ||
|
|
||
| private static comparePriorities(a: SyncPriorityStatus, b: SyncPriorityStatus) { | ||
| return b.priority - a.priority; // Reverse because higher priorities have lower numbers | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,32 +1,31 @@ | ||
| import { | ||
| type BucketStorageAdapter, | ||
| type PowerSyncBackendConnector, | ||
| type PowerSyncCloseOptions, | ||
| type RequiredAdditionalConnectionOptions, | ||
| AbstractPowerSyncDatabase, | ||
| DBAdapter, | ||
| DEFAULT_POWERSYNC_CLOSE_OPTIONS, | ||
| isDBAdapter, | ||
| isSQLOpenFactory, | ||
| PowerSyncDatabaseOptions, | ||
| PowerSyncDatabaseOptionsWithDBAdapter, | ||
| PowerSyncDatabaseOptionsWithOpenFactory, | ||
| PowerSyncDatabaseOptionsWithSettings, | ||
| SqliteBucketStorage, | ||
| StreamingSyncImplementation | ||
| StreamingSyncImplementation, | ||
| isDBAdapter, | ||
| isSQLOpenFactory, | ||
| type BucketStorageAdapter, | ||
| type PowerSyncBackendConnector, | ||
| type PowerSyncCloseOptions, | ||
| type RequiredAdditionalConnectionOptions | ||
| } from '@powersync/common'; | ||
| import { Mutex } from 'async-mutex'; | ||
| import { getNavigatorLocks } from '../shared/navigator'; | ||
| import { WebDBAdapter } from './adapters/WebDBAdapter'; | ||
| import { WASQLiteOpenFactory } from './adapters/wa-sqlite/WASQLiteOpenFactory'; | ||
| import { | ||
| DEFAULT_WEB_SQL_FLAGS, | ||
| ResolvedWebSQLOpenOptions, | ||
| resolveWebSQLFlags, | ||
| WebSQLFlags | ||
| WebSQLFlags, | ||
| resolveWebSQLFlags | ||
| } from './adapters/web-sql-flags'; | ||
| import { WebDBAdapter } from './adapters/WebDBAdapter'; | ||
| import { SharedWebStreamingSyncImplementation } from './sync/SharedWebStreamingSyncImplementation'; | ||
| import { SSRStreamingSyncImplementation } from './sync/SSRWebStreamingSyncImplementation'; | ||
| import { SharedWebStreamingSyncImplementation } from './sync/SharedWebStreamingSyncImplementation'; | ||
| import { WebRemote } from './sync/WebRemote'; | ||
| import { | ||
| WebStreamingSyncImplementation, | ||
|
|
@@ -160,14 +159,13 @@ export class PowerSyncDatabase extends AbstractPowerSyncDatabase { | |
| * By default the sync stream client is only disconnected if | ||
| * multiple tabs are not enabled. | ||
| */ | ||
| close(options: PowerSyncCloseOptions = DEFAULT_POWERSYNC_CLOSE_OPTIONS): Promise<void> { | ||
| close(options?: PowerSyncCloseOptions): Promise<void> { | ||
| if (this.unloadListener) { | ||
| window.removeEventListener('unload', this.unloadListener); | ||
| } | ||
|
|
||
| return super.close({ | ||
| // Don't disconnect by default if multiple tabs are enabled | ||
| disconnect: options.disconnect ?? !this.resolvedFlags.enableMultiTabs | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The default param above actually causes the opposite of this to occur. A |
||
| disconnect: options?.disconnect ?? !this.resolvedFlags.enableMultiTabs | ||
| }); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO remove this