How block-registry.ts maps filenames to AstroComponentFactory instances and how BlockRenderer resolves components at runtime.
The block registry is a single TypeScript file that auto-discovers every block component and exposes them as a unified lookup map. It is the mechanism that makes the page builder work without any manual registration.
The resulting key must match the name field in the Sanity schema for that block. Because defineBlock creates a Sanity object type with the name you provide, keeping the PascalCase filename and the camelCase schema name in sync is the only naming convention you need to follow.
The template block loop reads each *.astro file from ./blocks/ (the root of the blocks directory, not custom/) and uses the filename verbatim as the key:
const name = path.split('/').pop()!.replace('.astro', '');// 'hero-1'allBlocks[name] = (mod as { default: AstroComponentFactory }).default;
No transformation — the kebab-case filename becomes the _type string that must appear in Sanity.
allBlocks is a plain Record<string, AstroComponentFactory>. An AstroComponentFactory is the internal Astro type for a renderable component — exactly what you get from a .astro file’s default export.Only BlockRenderer imports allBlocks. Nothing else in the codebase references it directly.
block._type is the Sanity type name stored on each block in the blocks[] array.
allBlocks[block._type] either resolves to a component or is undefined.
If undefined, the block is skipped — the page renders without it and no error is thrown.
If resolved, the component receives every field on the block object as a top-level prop via {...block}.
If a block appears in Sanity but nothing renders on the page, the most common cause is a mismatch between the Sanity schema name and the filename-derived _type key. Check allBlocks in the browser’s Vite module graph or add a console.log(Object.keys(allBlocks)) in BlockRenderer to debug.
Earlier versions of similar projects use a switch (block._type) in the renderer with an explicit case for every block type. This creates a maintenance burden: every new block requires editing the renderer.The registry pattern eliminates that. Adding a block means:
Drop an .astro file in the right directory.
The import.meta.glob call picks it up at build time.
allBlocks gains the new key automatically.
No renderer edits. No registration file updates. No import lists.