@powersync/web 1.14.0 → 1.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.umd.js CHANGED
@@ -35605,6 +35605,9 @@ class SharedSyncImplementation extends _powersync_common__WEBPACK_IMPORTED_MODUL
35605
35605
  await this.waitForReady();
35606
35606
  // This effectively queues connect and disconnect calls. Ensuring multiple tabs' requests are synchronized
35607
35607
  return (0,_shared_navigator__WEBPACK_IMPORTED_MODULE_8__.getNavigatorLocks)().request('shared-sync-connect', async () => {
35608
+ if (!this.dbAdapter) {
35609
+ await this.openInternalDB();
35610
+ }
35608
35611
  this.syncStreamClient = this.generateStreamingImplementation();
35609
35612
  this.lastConnectOptions = options;
35610
35613
  this.syncStreamClient.registerListener({
@@ -35650,11 +35653,7 @@ class SharedSyncImplementation extends _powersync_common__WEBPACK_IMPORTED_MODUL
35650
35653
  return;
35651
35654
  }
35652
35655
  const trackedPort = this.ports[index];
35653
- if (trackedPort.db) {
35654
- trackedPort.db.close();
35655
- }
35656
- // Release proxy
35657
- trackedPort.clientProvider[comlink__WEBPACK_IMPORTED_MODULE_2__.releaseProxy]();
35656
+ // Remove from the list of active ports
35658
35657
  this.ports.splice(index, 1);
35659
35658
  /**
35660
35659
  * The port might currently be in use. Any active functions might
@@ -35665,12 +35664,22 @@ class SharedSyncImplementation extends _powersync_common__WEBPACK_IMPORTED_MODUL
35665
35664
  abortController.controller.abort(new _powersync_common__WEBPACK_IMPORTED_MODULE_0__.AbortOperation('Closing pending requests after client port is removed'));
35666
35665
  }
35667
35666
  });
35668
- if (this.dbAdapter == trackedPort.db && this.syncStreamClient) {
35669
- await this.disconnect();
35670
- // Ask for a new DB worker port handler
35671
- await this.openInternalDB();
35672
- await this.connect(this.lastConnectOptions);
35667
+ const shouldReconnect = !!this.syncStreamClient;
35668
+ if (this.dbAdapter && this.dbAdapter == trackedPort.db) {
35669
+ if (shouldReconnect) {
35670
+ await this.disconnect();
35671
+ }
35672
+ // Clearing the adapter will result in a new one being opened in connect
35673
+ this.dbAdapter = null;
35674
+ if (shouldReconnect) {
35675
+ await this.connect(this.lastConnectOptions);
35676
+ }
35677
+ }
35678
+ if (trackedPort.db) {
35679
+ trackedPort.db.close();
35673
35680
  }
35681
+ // Release proxy
35682
+ trackedPort.clientProvider[comlink__WEBPACK_IMPORTED_MODULE_2__.releaseProxy]();
35674
35683
  }
35675
35684
  triggerCrudUpload() {
35676
35685
  this.waitForReady().then(() => this.syncStreamClient?.triggerCrudUpload());
@@ -35744,6 +35753,10 @@ class SharedSyncImplementation extends _powersync_common__WEBPACK_IMPORTED_MODUL
35744
35753
  }
35745
35754
  async openInternalDB() {
35746
35755
  const lastClient = this.ports[this.ports.length - 1];
35756
+ if (!lastClient) {
35757
+ // Should not really happen in practice
35758
+ throw new Error(`Could not open DB connection since no client is connected.`);
35759
+ }
35747
35760
  const workerPort = await lastClient.clientProvider.getDBWorkerPort();
35748
35761
  const remote = comlink__WEBPACK_IMPORTED_MODULE_2__.wrap(workerPort);
35749
35762
  const identifier = this.syncParams.dbParams.dbFilename;