Principle:AFK surf Open agent Snapshot Materialization
| Knowledge Sources | |
|---|---|
| Domains | Import_Export, BlockSuite, CRDT_Sync |
| Last Updated | 2026-10-25 00:00 GMT |
Overview
Pattern of inserting a portable BlockSnapshot into a live doc store as real blocks, then propagating the mutation to peers and persistence via the configured CRDT sources.
Description
A BlockSnapshot is the portable, serializable representation of a block subtree. Transformer.snapshotToBlock(snapshot, store, rootId) materializes a snapshot into live blocks under a parent id in the target doc store. The Transformer is constructed with a Schema (registered with AffineSchemas), a blobCRUD adapter (for blob references), and a docCRUD adapter (for cross-doc links). After materialization, the blocks live in the yjs CRDT document; mutations are synced through the configured doc sources (BroadcastChannelDocSource, WebSocket, IndexedDB) and blob sources (MemoryBlobSource, IndexedDBBlobSource). This is the persistence step behind MarkdownTransformer.importMarkdownToBlock and the markdown-layout preset.
Usage
Apply this principle whenever you have a snapshot (from Markdown conversion, import, copy/paste, or cross-doc embedding) and need it to become editable, syncable blocks in a live document.
Theoretical Basis
Materialization is the inverse of serialization: snapshotToBlock: BlockSnapshot × Store × rootId → live blocks in CRDT. The transformer resolves block flavours against the schema, creates blobs via blobCRUD, and inserts the tree under rootId. The CRDT then propagates updates to all subscribed sources.
Pseudo-code:
for (const snapshot of snapshots) {
await transformer.snapshotToBlock(snapshot, store, rootId);
}