@abraca/dabra 2.29.0 → 2.31.0
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/abracadabra-provider.cjs +17 -2
- package/dist/abracadabra-provider.cjs.map +1 -1
- package/dist/abracadabra-provider.esm.js +17 -2
- package/dist/abracadabra-provider.esm.js.map +1 -1
- package/dist/index.d.ts +11 -0
- package/package.json +2 -2
- package/src/AbracadabraProvider.ts +14 -0
- package/src/BackgroundSyncManager.ts +21 -5
package/dist/index.d.ts
CHANGED
|
@@ -1379,6 +1379,17 @@ declare class AbracadabraProvider extends AbracadabraBaseProvider {
|
|
|
1379
1379
|
getChild(childId: string): AbracadabraProvider | null;
|
|
1380
1380
|
/** Check if a child provider is already loaded. */
|
|
1381
1381
|
hasChild(childId: string): boolean;
|
|
1382
|
+
/**
|
|
1383
|
+
* Whether a loaded child is currently transient — loaded with
|
|
1384
|
+
* `{ evictable: false }` (e.g. by a background indexer/sync) and not since
|
|
1385
|
+
* promoted to a normal UI-held child. A later `loadChild(id)` with the
|
|
1386
|
+
* default `evictable: true` clears this flag.
|
|
1387
|
+
*
|
|
1388
|
+
* Background loaders use this to decide whether they still own a child
|
|
1389
|
+
* before unloading it: if the UI opened the same doc mid-sync, the child is
|
|
1390
|
+
* no longer transient and must NOT be destroyed out from under the view.
|
|
1391
|
+
*/
|
|
1392
|
+
isChildTransient(childId: string): boolean;
|
|
1382
1393
|
/**
|
|
1383
1394
|
* Create (or return cached) a child AbracadabraProvider for a given
|
|
1384
1395
|
* child document id. Each child shares the parent's WebSocket via
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abraca/dabra",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.31.0",
|
|
4
4
|
"description": "abracadabra provider",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"abracadabra",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"yjs": "^13.6.8"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@abraca/schema": "2.
|
|
44
|
+
"@abraca/schema": "2.31.0"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
47
|
"test": "node --no-warnings --conditions=source --experimental-transform-types --test 'tests/*.test.ts'"
|
|
@@ -529,6 +529,20 @@ export class AbracadabraProvider extends AbracadabraBaseProvider {
|
|
|
529
529
|
return this.childProviders.has(childId);
|
|
530
530
|
}
|
|
531
531
|
|
|
532
|
+
/**
|
|
533
|
+
* Whether a loaded child is currently transient — loaded with
|
|
534
|
+
* `{ evictable: false }` (e.g. by a background indexer/sync) and not since
|
|
535
|
+
* promoted to a normal UI-held child. A later `loadChild(id)` with the
|
|
536
|
+
* default `evictable: true` clears this flag.
|
|
537
|
+
*
|
|
538
|
+
* Background loaders use this to decide whether they still own a child
|
|
539
|
+
* before unloading it: if the UI opened the same doc mid-sync, the child is
|
|
540
|
+
* no longer transient and must NOT be destroyed out from under the view.
|
|
541
|
+
*/
|
|
542
|
+
isChildTransient(childId: string): boolean {
|
|
543
|
+
return this.transientChildren.has(childId);
|
|
544
|
+
}
|
|
545
|
+
|
|
532
546
|
/**
|
|
533
547
|
* Create (or return cached) a child AbracadabraProvider for a given
|
|
534
548
|
* child document id. Each child shares the parent's WebSocket via
|
|
@@ -615,7 +615,13 @@ export class BackgroundSyncManager extends EventEmitter {
|
|
|
615
615
|
}
|
|
616
616
|
}
|
|
617
617
|
|
|
618
|
-
|
|
618
|
+
// Load transiently: a background-sync child must neither count toward
|
|
619
|
+
// the parent's LRU budget nor evict the user's open docs, and it must
|
|
620
|
+
// not be evicted out from under its own in-flight sync. We clean it up
|
|
621
|
+
// explicitly in `finally`.
|
|
622
|
+
const childProvider = await this.rootProvider.loadChild(docId, {
|
|
623
|
+
evictable: false,
|
|
624
|
+
});
|
|
619
625
|
|
|
620
626
|
try {
|
|
621
627
|
// Wait for ready (offline snapshot loaded) then synced (server sync done)
|
|
@@ -651,11 +657,21 @@ export class BackgroundSyncManager extends EventEmitter {
|
|
|
651
657
|
isE2E: false,
|
|
652
658
|
};
|
|
653
659
|
} finally {
|
|
654
|
-
//
|
|
655
|
-
//
|
|
656
|
-
//
|
|
660
|
+
// Release the provider only if we created it solely for background
|
|
661
|
+
// sync. Two cases keep it alive:
|
|
662
|
+
// - `alreadyCached`: it was loaded before we started — the UI owns it.
|
|
663
|
+
// - the user OPENED it mid-sync: `loadChild` (default evictable)
|
|
664
|
+
// promoted it out of transient, so it's no longer ours. Destroying
|
|
665
|
+
// it here would detach the provider under a doc they're viewing,
|
|
666
|
+
// leaving it stuck on a blue/"retrying" indicator until reload.
|
|
667
|
+
// `isChildTransient` is a newer provider API; fall back to the old
|
|
668
|
+
// unconditional unload if the parent predates it.
|
|
657
669
|
if (!alreadyCached) {
|
|
658
|
-
|
|
670
|
+
const stillOurs =
|
|
671
|
+
typeof (this.rootProvider as any).isChildTransient === "function"
|
|
672
|
+
? (this.rootProvider as any).isChildTransient(docId)
|
|
673
|
+
: true;
|
|
674
|
+
if (stillOurs) this.rootProvider.unloadChild(docId);
|
|
659
675
|
}
|
|
660
676
|
}
|
|
661
677
|
}
|