Skip to content

Commit 613aabc

Browse files
committed
Cleanup
1 parent 431ad0d commit 613aabc

File tree

4 files changed

+26
-20
lines changed

4 files changed

+26
-20
lines changed

demos/react-supabase-todolist/src/components/providers/SystemProvider.tsx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@ import { AppSchema, ListRecord, LISTS_TABLE, TODOS_TABLE } from '@/library/power
33
import { SupabaseConnector } from '@/library/powersync/SupabaseConnector';
44
import { CircularProgress } from '@mui/material';
55
import { PowerSyncContext } from '@powersync/react';
6-
import { createBaseLogger, DifferentialWatchedQuery, LogLevel, PowerSyncDatabase } from '@powersync/web';
6+
import {
7+
createBaseLogger,
8+
DifferentialWatchedQuery,
9+
LogLevel,
10+
PowerSyncDatabase,
11+
SyncClientImplementation,
12+
WASQLiteOpenFactory,
13+
WASQLiteVFS
14+
} from '@powersync/web';
715
import React, { Suspense } from 'react';
816
import { NavigationPanelContextProvider } from '../navigation/NavigationPanelContext';
917

@@ -12,9 +20,13 @@ export const useSupabase = () => React.useContext(SupabaseContext);
1220

1321
export const db = new PowerSyncDatabase({
1422
schema: AppSchema,
15-
database: {
16-
dbFilename: 'example.db'
17-
}
23+
database: new WASQLiteOpenFactory({
24+
dbFilename: 'example.db',
25+
vfs: WASQLiteVFS.OPFSCoopSyncVFS,
26+
flags: {
27+
enableMultiTabs: typeof SharedWorker !== 'undefined'
28+
}
29+
})
1830
});
1931

2032
export type EnhancedListRecord = ListRecord & { total_tasks: number; completed_tasks: number };
@@ -68,7 +80,7 @@ export const SystemProvider = ({ children }: { children: React.ReactNode }) => {
6880
const l = connector.registerListener({
6981
initialized: () => {},
7082
sessionStarted: () => {
71-
powerSync.connect(connector);
83+
powerSync.connect(connector, { clientImplementation: SyncClientImplementation.RUST });
7284
}
7385
});
7486

packages/web/src/db/adapters/LockedAsyncDatabaseAdapter.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -224,16 +224,13 @@ export class LockedAsyncDatabaseAdapter
224224
: null;
225225

226226
const id = LockedAsyncDatabaseAdapter.dbLockRequestId++;
227-
console.trace('Requesting database lock', this._dbIdentifier, id);
228-
return getNavigatorLocks()
229-
.request(`db-lock-${this._dbIdentifier}`, { signal: abortController.signal }, () => {
230-
this.pendingAbortControllers.delete(abortController);
231-
if (timoutId) {
232-
clearTimeout(timoutId);
233-
}
234-
return callback();
235-
})
236-
.finally(() => console.log('returning database lock', id));
227+
return getNavigatorLocks().request(`db-lock-${this._dbIdentifier}`, { signal: abortController.signal }, () => {
228+
this.pendingAbortControllers.delete(abortController);
229+
if (timoutId) {
230+
clearTimeout(timoutId);
231+
}
232+
return callback();
233+
});
237234
}
238235

239236
async readTransaction<T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions | undefined): Promise<T> {

packages/web/src/db/adapters/WorkerWrappedAsyncDatabaseConnection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ export class WorkerWrappedAsyncDatabaseConnection<Config extends ResolvedWebSQLO
149149
async close(): Promise<void> {
150150
// Abort any pending lock requests.
151151
this.lockAbortController.abort();
152-
await this.withRemote(() => this.baseConnection.close());
153152
this.options.remote[Comlink.releaseProxy]();
154153
this.options.onClose?.();
154+
await this.baseConnection.close();
155155
}
156156

157157
execute(sql: string, params?: any[]): Promise<ProxiedQueryResult> {

packages/web/src/worker/sync/SharedSyncImplementation.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,6 @@ export class SharedSyncImplementation extends BaseObserver<SharedSyncImplementat
349349
}
350350
}
351351

352-
if (trackedPort.db) {
353-
await trackedPort.db.close();
354-
}
355-
356352
// Re-index subscriptions, the subscriptions of the removed port would no longer be considered.
357353
this.collectActiveSubscriptions();
358354

@@ -488,6 +484,7 @@ export class SharedSyncImplementation extends BaseObserver<SharedSyncImplementat
488484
});
489485
lastClient.closeListeners.push(() => {
490486
this.logger.info('Aborting open connection because associated tab closed.');
487+
wrapped.close();
491488
wrapped.markRemoteClosed();
492489
});
493490

0 commit comments

Comments
 (0)