Composition / foldkit-composition

Migrations and unknown Blocks

Pages containing a Block removed from your Catalog remain readable: their nodes load, round-trip, render as placeholders, and can be reordered or deleted. validate reports unknown blocks so the strict publish schema blocks publishing until migrations update or remove them:

ts
const { document, applied, unused } = Composition.migrate(stored, [
  Composition.renameBlock('OldHeading', 'Heading'),
  Composition.renameProp('Heading', 'alignment', 'align'),
  Composition.promoteUnknown('LegacyVideo to Embed', 'LegacyVideo', Embed),
  Composition.migration('DangerToCritical', 'Callout', node =>
    node.props['tone'] === 'danger' ? { ...node, props: { ...node.props, tone: 'critical' } } : undefined,
  ),
])
// applied: [{ name, node }] in the order made; unused: names that rewrote nothing
  • The list is the chain. A later migration sees what an earlier one made.
  • A migration rewrites a node in place under its existing id, and the Document's structure is checked after each one that changed something: a Region pointing at nothing, a node placed twice, a cycle or a stranded node throws, naming the migration. What was already wrong before it ran is preserved.
  • The result is still content. A rewritten node must decode as a Node.
  • Declining is allowed. Returning undefined keeps the node. promoteUnknown declines when a node's props fail to decode under the target Block, keeping it intact rather than half-converted.
  • Run migrations at explicit boundaries, such as on load, before a publish, or in a backfill script.

An unknown Block can still be reordered within its current Region or roots, and removed; moving it across Regions or editing its props waits until a migration promotes it.

Performance

Measured across a 1,000-node page in the package benchmark suite:

OperationMeasured meanBudget
apply one setProp0.40 ms1 ms
apply one move between sections0.39 ms1 ms
validate the whole page1.14 ms10 ms
index a page0.09 ms5 ms

apply shares every unchanged node and copies the nodes record once per Operation, which accounts for most of its cost at this size.

Relationship to rich text

A page and a rich-text document serve different granularity: rich text edits by character position, while a page edits by Block and Region. You can embed rich text inside a Block prop with foldkit-composition/richtext, keeping the vocabulary at module scope and stored props as JSON.

Limits

  • A condition is one of four operations over one context key; or and not combinators are omitted, matching Expr.
  • Only a token choice is responsive; a variant keeps one value across viewports.

Next

  • Build an interactive page editor with undo, selection, and clipboard: foldkit-builder.
  • Render the full page editor UI with accessible keyboard and drag support: foldkit-mixins-builder.
  • Add drafts, revisions, and scheduled publishing to pages: foldkit-cms.