NewsCrawler.org

How the Block architecture of online documents works

In online document editors, the Block[1] architecture builds a document, called a Page, out of blocks such as text, images, tables, charts, code and third-party components. Instead of one large nested JSON, every block receives a stable id and is stored in a flat recordMap, with nesting and order expressed through id arrays; the price is extra storage, in exchange for offline creation, fine-grained collaboration, partial caching and stable references. Loading starts from the document snapshot: block order and sizes are enough to lay out the page before block contents arrive, a Page keeps only its direct children, and a block's internal data is lazy-loaded once the block comes near the viewport.

Large documents are fetched in chunks — the example response carries 20 records, a hasMore flag and a cursor token that the client passes back unchanged — while oversized blocks are listed in an ignore_blocks field and pulled separately; data that is downloaded is not necessarily moved into memory, and data in memory is not necessarily rendered. Rendering relies on virtual scrolling[2]: only blocks near the viewport are mounted, distant ranges are merged into placeholders with cumulative heights, and buffer zones above and below preload data and components to reduce blank screens during fast scrolling. A LayoutTree[3] stores each block's top and height; blocks without a measured height get a default fallback value that is corrected after rendering, and scrollTop is compensated so that a height change does not push the visible block off screen. Blocks report their own height changes — after an image finishes loading, text content changes or a font is loaded and applied — instead of relying on MutationObserver.

Rich text is compressed by separating the plain text, an attribute-application string such as *0+6*1+5, and a shared attribute pool (aPool), which is the structure that actually gets persisted to the database. For collaboration, the otjson[4] algorithm fits this domain: edits are reduced to three atomic operations — insert, retain and delete — and each block carries a version field.

Read the original juejin.cn

Discussion

The single top comment is a short playful joke unrelated to the technical content of the post.

Sources

  • CNJuejin ZH

    🔥说一说在线文档的 Block 架构是如何实现的

    11 likes639 views5 comments11 saves

Published: First seen: Читать по-русски

Open as a page