Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .changeset/block-renderers-module.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
'@tanstack/cms-core': minor
'@tanstack/cms-ui-react': minor
---

**Breaking:** block renderers move out of `blockTypes`. `BlockType.component`
is removed, so a block type is data only (`type`, `label`, `fields`) and the
config never imports React. `defineBlock`, `defineCms`, and plugins throw when a
block type still has a `component`, naming where it goes.

Export the components from a renderers module with `defineRenderers()` (from
`@tanstack/cms-ui-react` or `/site`) and name its path, relative to the routes
directory, in `createRoutes(definition, { renderers })`. The CMS's own routes
(public pages, preview, on-page editor) render blocks with it; the
`tanstackCms()` Vite plugin hands it to them, so `vite.config.ts` passes a path
and never loads React. In your own routes, pass the same object to
`BlocksView`, `BlockView`, or `InteractiveDocument` as the new `renderers` prop.
A block's renderer is the prop's, then the module's, then a built-in, then the
generic field view; an app renderer can replace a built-in.

```tsx
// src/cms.renderers.tsx
import { defineRenderers } from '@tanstack/cms-ui-react/site'
export const renderers = defineRenderers({ blocks: { quote: Quote } })

// vite.config.ts
createRoutes(definition, { renderers: '../cms.renderers.tsx' })
```
7 changes: 4 additions & 3 deletions .claude/skills/astro-starlight-to-tanstack-cms/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@ a `hero` block; translations can become `locale`/`translationOf` documents).
Block palette: a docs migration only needs `richText` (`markdown` field
type). Add block types only if you decompose bodies into something richer
than one Markdown blob; the renderer has built-in `callout`, `code`,
`columns`, `embed`, `image`, `cta`, and `hero` components, and
`defineBlock({ component })` takes a custom one.
`columns`, `embed`, `image`, `cta`, and `hero` components, and the app's
renderers module (`defineRenderers({ blocks })`, named by
`createRoutes(definition, { renderers })`) adds a custom one.

## 4. Migrate the data

Expand Down Expand Up @@ -204,7 +205,7 @@ Always consider:

- **MDX components** — every component flattened by the migrator (it prints
the list). Each needs a block type + renderer to restore its behavior
(`defineBlock({ component })`), or stays text-only.
(`defineBlock` plus a `defineRenderers({ blocks })` entry), or stays text-only.
- **Explicit sidebars** — the docs layout derives groups from slug segments;
hand-written `sidebar` entries (external links, custom group labels,
`sidebar.badge`, `sidebar.hidden`) need app work.
Expand Down
3 changes: 2 additions & 1 deletion .claude/skills/emdash-to-tanstack-cms/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ For a migrated post that's `imageField: 'hero'`, `summaryField: 'excerpt'`,

The renderer has built-in components for `hero`, `richText`, `image`, `cta`,
`callout`, `code`, `columns`, and `embed`; other block types use the generic
renderer or a `defineBlock({ component })`.
renderer or a custom one in the app's renderers module
(`defineRenderers({ blocks })`, named by `createRoutes(definition, { renderers })`).

## 4. Migrate the data

Expand Down
5 changes: 3 additions & 2 deletions .claude/skills/payload-to-tanstack-cms/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,9 @@ with fields mapped by the same table. A block's Lexical `content` usually
becomes the `richText` block's `markdown` field. The renderer in
`@tanstack/cms-ui-react` has built-in components for `hero`, `richText`,
`image`, `cta`, `callout`, `code`, `columns`, and `embed`; any other block
type renders with the generic field renderer, or pass a `component` in
`defineBlock` for a custom one.
type renders with the generic field renderer, or add a custom one to the
app's renderers module (`defineRenderers({ blocks })`, named by
`createRoutes(definition, { renderers })`).

## 4. Migrate the data

Expand Down
4 changes: 3 additions & 1 deletion .claude/skills/wordpress-to-tanstack-cms/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ SEO tags (`cmsHead`), the home page's post cards, and the on-page editor read.
Post body block palette: `richText` (`markdown` field type) covers converted
bodies. The renderer also has built-in `hero`, `image`, `cta`, `callout`,
`code`, `columns`, and `embed` components; use `htmlToBlocks` (§5) to emit
them, or `defineBlock({ component })` for custom Gutenberg blocks.
them, or a `defineBlock` plus a renderer in the app's renderers module
(`defineRenderers({ blocks })`, named by `createRoutes(definition, { renderers })`)
for custom Gutenberg blocks.

## 4. Migrate the data

Expand Down
4 changes: 2 additions & 2 deletions docs/api/cms-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ function defineCollection<const TCollection extends Collection>(collection: TCol
function defineBlock<const TBlock extends BlockType>(block: TBlock): TBlock
```

Identity helpers that keep literal types for `InferDoc` / `InferBlock`.
Identity helpers that keep literal types for `InferDoc` / `InferBlock`. `defineBlock` throws when the block type has a `component`: block renderers live in the app's renderers module (see [Custom block renderers](../schema/blocks-and-rendering#custom-block-renderers)).

### `collections()`, `blockTypes()`, `blockTypeMap()`

Expand Down Expand Up @@ -773,7 +773,7 @@ function isFieldVisible(field: Field, siblings: Record<string, JsonValue | undef
| `CollectionAdmin` | `{ columns?: Array<string>; defaultSort?: { field: string; dir?: 'asc' \| 'desc' } }`. |
| `CollectionHooks` | Pre-commit lifecycle hooks: `preValidate`, `postValidate`, `preDelete`, plus the `postRead` response transform. `afterChange` / `afterDelete` are deprecated in favour of `defineEventHandler`. See [Events & Hooks](../architecture/events-and-hooks). |
| `ChangeHookArgs` | `{ doc, id, operation, actor }` — what a pre-commit mutating hook receives. |
| `BlockType` | `{ type, label, fields, component? }`. |
| `BlockType` | `{ type, label, fields }`. Data only: renderers are bound with `defineRenderers` from `@tanstack/cms-ui-react`, and a block type with a `component` throws. |
| `Block` | `{ _type: string } & { [key: string]: JsonValue }`. |
| `Doc` | `{ [key: string]: JsonValue }`. |
| `JsonValue` | Any JSON value. |
Expand Down
32 changes: 29 additions & 3 deletions docs/api/cms-ui-react.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ interface BlocksViewProps {
blocks: ReadonlyArray<Block>
className?: string // default 'space-y-8'
onSelectBlockField?: (blockIndex: number, fieldName: string) => void
renderers?: CmsRenderers
}
```

Renders an ordered array of blocks with your `defineCms({ blockTypes })` components, falling back to the built-in renderers. See [Blocks & Rendering](../schema/blocks-and-rendering).
Renders an ordered array of blocks. Each block's renderer is `renderers.blocks[_type]` from the prop, then from the renderers module bound through `createRoutes(definition, { renderers })`, then a built-in renderer, then a generic view of its fields. See [Blocks & Rendering](../schema/blocks-and-rendering#custom-block-renderers).

### `BlockView`

Expand All @@ -64,11 +65,29 @@ function BlockView(props: BlockViewProps): JSX.Element
interface BlockViewProps {
block: Block
onSelectField?: (fieldName: string) => void
renderers?: CmsRenderers
}
```

Renders a single block.

### `defineRenderers(renderers)`

```ts
function defineRenderers(renderers: CmsRenderers): CmsRenderers

interface CmsRenderers {
blocks?: { readonly [type: string]: ComponentType<BlockRendererProps> }
}

interface BlockRendererProps {
block: Block
onSelectField?: (fieldName: string) => void
}
```

Declares the app's React renderers, keyed by block `_type`; exported from both the package root and `/site`. It checks the shape and returns the object. Export the result as `renderers` from a module (e.g. `src/cms.renderers.tsx`), name that module's path in `createRoutes(definition, { renderers })` for the CMS's own routes, and pass the object as the `renderers` prop in your own. Block types stay data only: `defineBlock`, `defineCms`, and plugins reject a block type with a `component`.

```tsx validate=type
import { BlocksView } from '@tanstack/cms-ui-react/site'
import type { Block } from '@tanstack/cms-core'
Expand Down Expand Up @@ -372,6 +391,7 @@ interface CreateRoutesSpec {
api?: CmsRouteSurfaceSpec<'api'>
custom?: ReadonlyArray<VirtualRouteNode>
rootFile?: string
renderers?: string // the app's renderers module, relative to the routes directory
}

// true: every route; false: none; a key list: only those;
Expand All @@ -390,7 +410,7 @@ type CmsRouteKey =
type CmsSurfaceRouteKey<S extends CmsRouteSurface> // the keys of one surface
```

The virtual route tree for the TanStack Router plugin: the public pages, the admin, and the API routes, plus your own `custom` routes. The admin base path and plugin routes come from the definition. A surface you leave out is mounted, so `createRoutes(definition)` mounts everything. Route keys are stable public API: renaming or removing one is a breaking change. Keys, paths, and options are listed in the [route table](./routes-and-endpoints#route-table); overriding and adding routes is covered in [Building Pages](../schema/building-pages).
The virtual route tree for the TanStack Router plugin: the public pages, the admin, and the API routes, plus your own `custom` routes. The admin base path and plugin routes come from the definition. A surface you leave out is mounted, so `createRoutes(definition)` mounts everything. `renderers` is the path of a module that exports `renderers = defineRenderers({ … })`; the CMS routes render blocks with it. It is a path rather than an import so `vite.config.ts` never loads React, and it must exist when the config loads. Route keys are stable public API: renaming or removing one is a breaking change. Keys, paths, and options are listed in the [route table](./routes-and-endpoints#route-table); overriding and adding routes is covered in [Building Pages](../schema/building-pages).

---

Expand All @@ -410,10 +430,16 @@ interface CmsVitePlugin {
ssr: { noExternal: Array<string | RegExp> }
optimizeDeps: { exclude: Array<string> }
}
resolveId: (
id: string,
importer: string | undefined,
options?: { ssr?: boolean },
) => string | undefined
load: (id: string) => string | undefined
}
```

The CMS packages ship TanStack Start server functions and route files that your app's Start compiler must transform. The plugin keeps `@tanstack/cms-core`, `@tanstack/cms-api`, `@tanstack/cms-ui-react`, and `@tanstack/cms-client` (plus any `packages` you add) out of Vite's SSR externals and dependency pre-bundling, and bundles `@tanstack/ai*` into SSR alongside them. `routesDirectory` and `generatedDirectory` are read by `createRoutes()`, which resolves route files when the config loads. Add it before `tanstackStart()`.
The CMS packages ship TanStack Start server functions and route files that your app's Start compiler must transform. The plugin keeps `@tanstack/cms-core`, `@tanstack/cms-api`, `@tanstack/cms-ui-react`, and `@tanstack/cms-client` (plus any `packages` you add) out of Vite's SSR externals and dependency pre-bundling, and bundles `@tanstack/ai*` into SSR alongside them. In SSR, `resolveId` and `load` serve `use-sync-external-store` as ESM on React's own `useSyncExternalStore`, so a production server bundle under pnpm loads one React. `routesDirectory` and `generatedDirectory` are read by `createRoutes()`, which resolves route files when the config loads. When `createRoutes(definition, { renderers })` names a renderers module, the plugin's `load` hook serves the package's `app-renderers` module (which every CMS page route imports) as code that binds it. Add it before `tanstackStart()`.

```ts validate=type
import { defineConfig } from 'vite'
Expand Down
1 change: 1 addition & 0 deletions docs/api/routes-and-endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Admin paths move under the definition's `admin.basePath` when one is set (for ex
| `api` | surface spec | `true` | The API routes. |
| `custom` | `Array<VirtualRouteNode>` | none | Your app's own routes, built with `route()` / `index()` / `physical()` from `@tanstack/virtual-file-routes`, attached after the CMS and plugin routes. |
| `rootFile` | `string` | package `__root.tsx` | Your own root route file. |
| `renderers` | `string` | none | Your renderers module (`export const renderers = defineRenderers({ blocks })`), relative to the routes directory. The CMS routes render blocks with it. See [Custom block renderers](../schema/blocks-and-rendering#custom-block-renderers). |

Each surface takes the same values:

Expand Down
1 change: 1 addition & 0 deletions docs/architecture/routes-in-a-package.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ The spec says what to mount; with no spec, everything is mounted.
| `public`, `admin`, `api` | Per surface: `true` or left out (every route), `false` (none), `['review']` (only these keys), or `{ agent: false, edit: './edit.tsx' }` (drop or replace single keys) |
| `custom` | Your app's own routes (`route()`, `index()`, `physical()`), attached after the CMS and plugin routes |
| `rootFile` | Your own root route instead of the package's `__root.tsx` |
| `renderers` | Path of your renderers module (`export const renderers = defineRenderers({ blocks })`); the CMS routes render blocks with it. See [Custom block renderers](../schema/blocks-and-rendering#custom-block-renderers) |

The admin base path and plugin routes aren't options: they come from the definition. The build directories are options of `tanstackCms()`:

Expand Down
21 changes: 21 additions & 0 deletions docs/deployment/upgrading.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,27 @@ createRoutes(definition, {

`tanstackCms()` has to come before `tanstackStart()` in `plugins`, because `createRoutes()` reads its `routesDirectory` and `generatedDirectory` when Start loads the router config. The route keys (`CmsRouteKey`, and `CMS_ROUTE_KEYS` from `@tanstack/cms-core/definition`) are stable public API.

### 22. Block renderers move out of `blockTypes`

`BlockType.component` is removed, so block types are data only and the config never imports React. `defineBlock`, `defineCms`, and plugins throw when a block type still has a `component`. Move each component into a renderers module and name its path in `createRoutes`; the CMS's own routes (public pages, preview, on-page editor) render with it. In your own routes, pass the same object to `BlocksView`, `BlockView`, or `InteractiveDocument` as `renderers`.

```tsx
// before: src/cms.config.ts
defineBlock({ type: 'quote', label: 'Quote', fields, component: Quote })

// after: src/cms.config.ts
defineBlock({ type: 'quote', label: 'Quote', fields })

// after: src/cms.renderers.tsx
import { defineRenderers } from '@tanstack/cms-ui-react/site'
export const renderers = defineRenderers({ blocks: { quote: Quote } })

// after: vite.config.ts (a path, relative to src/routes)
createRoutes(definition, { renderers: '../cms.renderers.tsx' })
```

There's no codemod: the components usually sit inline in the config and need their imports moved with them. The built-in renderers (`hero`, `richText`, …) are unchanged, and a `renderers.blocks` entry with the same `_type` replaces one. See [Custom block renderers](../schema/blocks-and-rendering#custom-block-renderers).

## Versioning policy

From 1.0, TanStack CMS follows [semantic versioning](https://semver.org). The
Expand Down
4 changes: 2 additions & 2 deletions docs/migration/from-astro-starlight.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Where the [Payload migration](./from-payload) converts Lexical JSON, Starlight c
| **Runtime** | Build-time static site; every edit is a commit and a rebuild | A TanStack Start server; edits publish immediately, or through the review queue |
| **Storage** | `.md`/`.mdx` files in git | A `StorageAdapter` (`createSqliteStorage()` by default, `createLibsqlStorage()` for Turso), with a revision per commit |
| **Schema** | Content collections with `docsSchema()` frontmatter | `defineCms({ collections, blockTypes })` with `theme: { variant: 'docs' }` |
| **Components** | MDX with compile-time JSX (`<Card>`, `<Aside>`, `<Tabs>`) | Markdown plus typed blocks; custom blocks take a React `component` |
| **Components** | MDX with compile-time JSX (`<Card>`, `<Aside>`, `<Tabs>`) | Markdown plus typed blocks; custom blocks get a React renderer from the app's renderers module |
| **Navigation** | `sidebar` config or `autogenerate` | The docs layout builds the sidebar from the `page` collection: grouped by the first slug segment, ordered by `sidebarOrder`, labelled by `sidebarLabel` |
| **Authoring** | A code editor and pull requests | The admin (`/content`, `/edit/page/$id`), on-page editing, and agents through MCP, all staged for review where needed |
| **URLs** | `/start/installation/` | `/p/start-installation`, with a `redirect` document for every old URL |
Expand Down Expand Up @@ -133,7 +133,7 @@ The migrator also writes `src/seed-data.ts`; `defineCms({ seed: { documents: see

## Remaining Gaps

- **MDX components**: flattened to Markdown; restoring interactive behavior needs a block type with a `component`.
- **MDX components**: flattened to Markdown; restoring interactive behavior needs a block type and a renderer for it (see [Custom block renderers](../schema/blocks-and-rendering#custom-block-renderers)).
- **MDX expressions**: `{expressions}` and `export const` values aren't evaluated.
- **Hand-written sidebars**: groups come from slug segments, so external links, custom group labels, `sidebar.badge`, and `sidebar.hidden` need app work. Group labels are the title-cased first slug segment (`start` shows as "Start here"), not the `label` from `astro.config.mjs`.
- **Splash pages**: `template: splash`, `hero`, `banner`, `prev`/`next`, and `tableOfContents` aren't mapped; the home page becomes an ordinary page (a `hero` block can stand in).
Expand Down
2 changes: 1 addition & 1 deletion docs/migration/from-payload.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Field options carry over by name: `required`, `unique`, `index`, `defaultValue`,
| `banner` / `callout` | `callout` | `tone`, `title`, `markdown` |
| `code` | `code` | `language`, `filename`, `code` |

The renderer in `@tanstack/cms-ui-react` has components for `hero`, `richText`, `image`, `cta`, `callout`, `code`, `columns`, and `embed`. Other block types render with a generic field renderer, or with the `component` you pass to `defineBlock`.
The renderer in `@tanstack/cms-ui-react` has components for `hero`, `richText`, `image`, `cta`, `callout`, `code`, `columns`, and `embed`. Other block types render with a generic field renderer, or with a renderer from your renderers module (see [Custom block renderers](../schema/blocks-and-rendering#custom-block-renderers)).

## 1. Map the Schema

Expand Down
Loading
Loading