Heuristic:AFK surf Open agent Blob Source Shadow Persistence
| Knowledge Sources | |
|---|---|
| Domains | Optimization, Storage, Sync |
| Last Updated | 2026-10-25 00:00 GMT |
Overview
Configure the in-memory MemoryBlobSource as the blob `main` and add durable sources (IndexedDBBlobSource, MockServerBlobSource) only as shadows to keep reads fast while enabling persistence/sync in the background.
Description
BlockSuite's blob pipeline uses a `main` + `shadows` split. The `main` source is the primary read/write store; `shadows` are mirrored in the background. In the playground starter, `MemoryBlobSource` is always the `main` (fast, in-RAM), and `IndexedDBBlobSource` (browser-persistent) and/or `MockServerBlobSource` (simulated remote) are pushed into `shadows` only when requested via the `?blobSource=` URL parameter. This keeps the default editor snappy while letting users opt into durable persistence for testing.
Usage
Apply this heuristic when configuring a DocCollection/`TestWorkspace` blob source set and you want fast in-memory reads plus optional durable persistence. It is especially useful in playground/test contexts where most runs don't need IndexedDB, but some tests/demos do.
The Insight (Rule of Thumb)
- Action: Set `blobSources.main = new MemoryBlobSource()` and push durable/remote sources into `blobSources.shadows` only when needed.
- Value: `main` = `MemoryBlobSource` always; `shadows` = `IndexedDBBlobSource` and/or `MockServerBlobSource` gated on the `?blobSource=idb,mock` URL param.
- Trade-off: Default (no shadows) loses blobs on reload — acceptable for ephemeral demos; durable storage is opt-in.
- Compatibility: Works with any `BlobSource` implementation; the `shadows` array is part of `DocCollectionOptions['blobSources']`.
Reasoning
The `main` source is on the hot read path for every blob fetch (attachments, images). Using an in-memory store there avoids IndexedDB transaction latency on every render. Shadows are written asynchronously and do not block reads, so durability is layered on without slowing the editor. The `?blobSource=` opt-in keeps the default experience lightweight.
Code Evidence
Blob source assembly from `blocksuite/playground/apps/starter/utils/collection.ts:42-51`:
const blobSources = {
main: new MemoryBlobSource(),
shadows: [] as BlobSource[],
} satisfies DocCollectionOptions['blobSources'];
if (blobSourceArgs.includes('mock')) {
blobSources.shadows.push(new MockServerBlobSource(collectionId));
}
if (blobSourceArgs.includes('idb')) {
blobSources.shadows.push(new IndexedDBBlobSource(collectionId));
}