@pylonsync/sync 0.3.201 → 0.3.202

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.ts +21 -1
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.3.201",
6
+ "version": "0.3.202",
7
7
  "type": "module",
8
8
  "main": "src/index.ts",
9
9
  "types": "src/index.ts",
package/src/index.ts CHANGED
@@ -1495,7 +1495,27 @@ export class SyncEngine {
1495
1495
  this.lastSeenTenant !== undefined &&
1496
1496
  this.lastSeenTenant !== tenantNow
1497
1497
  ) {
1498
- await this.resetReplica();
1498
+ // Two flavors of "tenant changed":
1499
+ //
1500
+ // - null → X : session first-resolution. The engine started
1501
+ // before the app called /api/auth/select-org;
1502
+ // /api/auth/me returned tenant_id=null at start
1503
+ // and is only now reporting the real value.
1504
+ // The cached IndexedDB rows ARE for tenant X
1505
+ // (that's where the user's data lives), so
1506
+ // wiping them would tombstone valid state and
1507
+ // produce the "rows render then flash away"
1508
+ // symptom multi-tenant apps were hitting. Skip
1509
+ // the reset; pull under the new tenant fills
1510
+ // any gaps via the existing cursor catch-up.
1511
+ //
1512
+ // - X → Y : actual org switch. Cached rows belong to
1513
+ // the OLD tenant and must not bleed into the
1514
+ // new context, so resetReplica is correct.
1515
+ const firstResolution = this.lastSeenTenant === null && tenantNow !== null;
1516
+ if (!firstResolution) {
1517
+ await this.resetReplica();
1518
+ }
1499
1519
  await this.pull();
1500
1520
  }
1501
1521
  this.lastSeenTenant = tenantNow;