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
47 changes: 47 additions & 0 deletions .changeset/remove-role-cascades.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
'@tanstack/cms-core': minor
'@tanstack/cms-ui-react': minor
'@tanstack/cms-ui-dom': minor
---

**Breaking, and silent:** content roles are no longer guessed from field
names. Pages keep rendering, but collections that don't declare their roles
lose these values with no error:

- `cmsHead` / `cmsJsonLd`: the meta and OpenGraph description, the social
image, JSON-LD `datePublished`, and the JSON-LD author. They no longer try
fields named `excerpt`/`description`/`summary`/`subheading`,
`hero`/`image`/`coverImage`/`featuredImage`/`cover`,
`publishedDate`/`publishAt`/`date`, or `author`, and no longer take the first
block's `subheading` or `image`. The title reads only `titleField`, not a
field named `title` as well.
- The on-page post editor and the home page's post cards: the summary and
byline. Without a collection, the on-page editor only assumes `title`.
- `getSummaryField()` and `getBylineField()` return only the declared
`summaryField` / `bylineField`.

What's still inferred is one rule per role, on field types: the first `image`
field is the image, the first `markdown` or `richtext` field (other than the
summary) is the body, the first `blocks` field holds the blocks, and a field
named `slug` is the slug. Everything else must be declared (`summaryField`,
`bylineField`, `dateField`, …).

Built-in blocks read one field name each. `renderBlockToHtml` /
`renderBlocksToHtml` (`@tanstack/cms-ui-dom`) now match the React renderer and
the docs: the `image` block reads `image` (was `src`), the `callout` block
reads `markdown` (was `body`), and the aliases `hero.headline`,
`hero.subheadline`, `richText.body`, `quote.body`, and `quote.author` are gone.
The React `callout` block no longer reads `body`.

To keep today's output, declare the roles the fallbacks used to pick with the
codemod from a TanStack/cms checkout, review the diff, then upgrade:

```sh
pnpm codemod explicit-roles --dry /path/to/your/app
pnpm codemod explicit-roles /path/to/your/app
```

Blocks-only collections have no field to declare for the description or image
that used to come from the first block. Add an `seoField()` (and fill
`seo.description` / `seo.image`), or a summary or image field declared as the
role.
4 changes: 2 additions & 2 deletions .claude/skills/emdash-to-tanstack-cms/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ tables you used, the Portable Text coverage, how the content was loaded, and a
- **Hierarchical taxonomies** — flattened into a `multiselect` (parents lost),
or modelled as a collection + `relation`. Taxonomy archive pages
(`/category/<slug>`) need an app route (`queryDocuments({ where })`).
- **Bylines** — the built-in post page renders the plain-text `author` field,
not the `authors` relation; byline roles and ordering beyond the array order
- **Bylines** — the built-in post page renders the plain-text `author` field
(declared as `bylineField`), not the `authors` relation; byline roles and ordering beyond the array order
need app work.
- **Menus / widget areas / sections / settings** — site chrome with no core
analogue; rebuild in app code or a singleton collection (`isSingleton`).
Expand Down
2 changes: 1 addition & 1 deletion docs/agents/on-page-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Three components from `@tanstack/cms-ui-react/site` drive this:

- **`InteractiveDocument({ id, doc, collection })`** (also exported as `unstable_InteractiveDocument`) automatically dispatches to `InteractivePageContent` when the collection defines a `blocks` field (`collection.blocksField` or its first `blocks` field), or `InteractivePostContent` otherwise, and disables inline editing for read-only collections (such as `createMarkdownStorage`).
- **`InteractivePageContent({ id, doc, collection? })`** (also `unstable_InteractivePageContent`) renders and edits a page's title and blocks array (`collection.blocksField`, default `'blocks'`). `collection` defaults to `'page'`.
- **`InteractivePostContent({ id, doc, collection? })`** (also `unstable_InteractivePostContent`) renders and edits a flat document's configured field roles: `titleField`, `bylineField` (fallback `author`), `summaryField` (fallback `excerpt`/`description`), `imageField` (fallback first `image` field), and `bodyField` (fallback first `markdown` or `richtext` field). `collection` defaults to `'post'`.
- **`InteractivePostContent({ id, doc, collection? })`** (also `unstable_InteractivePostContent`) renders and edits a flat document's declared field roles: `titleField`, `bylineField`, `summaryField`, `imageField` (default: the first `image` field), and `bodyField` (default: the first `markdown` or `richtext` field). Undeclared bylines and summaries aren't shown. `collection` defaults to `'post'`.

## Who Sees What

Expand Down
8 changes: 4 additions & 4 deletions docs/api/cms-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ interface CmsJsonLdOptions {
}
```

schema.org data for a document: `headline` (article types) or `name`, `description` (the `summaryField`), `image`, `url`, `datePublished` (the `dateField`; without one, `publishedDate`, `publishAt`, or `date`), `dateModified` (`_updatedAt`), and `author` (the `bylineField`).
schema.org data for a document: `headline` (article types) or `name`, `description` (the `summaryField`), `image`, `url`, `datePublished` (the `dateField`), `dateModified` (`_updatedAt`), and `author` (the `bylineField`).

### `seoField()`

Expand Down Expand Up @@ -598,9 +598,9 @@ function slugify(input: string): string
function getBlocksField(collection: Collection): string | undefined // blocksField, else first `blocks` field
function getImageField(collection: Collection): string | undefined // imageField, else first `image` field
function getSlugField(collection: Collection): string | undefined // slugField, else a field named `slug`
function getSummaryField(collection: Collection): string | undefined // summaryField, else `excerpt`/`description`/`summary`/`subheading`
function getBylineField(collection: Collection): string | undefined // bylineField, else a text field named `author`
function getBodyField(collection: Collection): string | undefined // bodyField, else first `markdown`, then `richtext`, field
function getSummaryField(collection: Collection): string | undefined // summaryField
function getBylineField(collection: Collection): string | undefined // bylineField
function getBodyField(collection: Collection): string | undefined // bodyField, else first `markdown` or `richtext` field that isn't the summary
function getDateField(collection: Collection): string | undefined // dateField
function getCollectionRoles(collection: Collection): CollectionRoles // { title, slug, blocks, image, summary, byline, body, date }
function normalizeFieldOptions(options?: ReadonlyArray<FieldOption>): Array<NormalizedFieldOption>
Expand Down
2 changes: 1 addition & 1 deletion docs/api/cms-ui-react.md
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ The on-page editor components are exported from `@tanstack/cms-ui-react/site` (w
| --- | --- |
| `InteractiveDocument` (`unstable_InteractiveDocument`) | `({ id, doc, collection })`. Dispatches to `InteractivePageContent` when the collection defines a `blocks` field (`blocksField`, or its first `blocks` field) or to `InteractivePostContent` otherwise, and disables inline editing for read-only collections. |
| `InteractivePageContent` (`unstable_InteractivePageContent`) | `({ id, doc, collection? = 'page' })`. Renders a page's blocks with on-page editing for sessions with `content.write`: hold Ctrl or Option and click a title or block to edit inline, reorder, add, or remove blocks, or ask AI to edit the selection or the whole page. Reads and writes the collection's blocks field (`blocksField`, or its first `blocks` field). |
| `InteractivePostContent` (`unstable_InteractivePostContent`) | `({ id, doc, collection? = 'post' })`. The same for flat documents. It edits the title (`titleField`), byline (`bylineField`, or a text field named `author`), summary (`summaryField`, or `excerpt`/`description`), featured image (`imageField`, or the first `image` field), and body (`bodyField`, or the first `markdown`, then `richtext`, field). |
| `InteractivePostContent` (`unstable_InteractivePostContent`) | `({ id, doc, collection? = 'post' })`. The same for flat documents. It edits the collection's roles: title (`titleField`), byline (`bylineField`), summary (`summaryField`), featured image (`imageField`, or the first `image` field), and body (`bodyField`, or the first `markdown` or `richtext` field). An undeclared byline or summary isn't shown. |
| `SelectedPageObject` (`unstable_SelectedPageObject`) | `{ kind: 'title' } \| { kind: 'block'; index; focusField? } \| null` |
| `SelectedPostObject` (`unstable_SelectedPostObject`) | `{ kind: 'field'; field: string } \| null` |
| `unstable_WebMcpBadge` | Exposes the agent tools to in-browser agents through WebMCP (MCP-B), for sessions with `agent.use`. Tool calls go to `POST /api/cms` and their writes are staged for review. The package root route renders it. |
Expand Down
2 changes: 1 addition & 1 deletion docs/deployment/upgrading.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ import { BlocksView, SiteShell } from '@tanstack/cms-ui-react/site'

- **JSON-LD and `og:type`.** These used to switch on a collection named `post`. Set `schemaType: 'BlogPosting'` (or `'Article'`, …) on the collection instead. Without it, documents are a `WebPage` with `og:type` `website`.
- **The "View" link.** The admin's "View page" and "View post" links are replaced by one "View on site" link, which appears for any collection that defines `path`.
- **The on-page editor and starter home page.** These read the collection's `titleField`, `bylineField`, `summaryField`, `imageField`, and `bodyField`. Each falls back to the old conventions (`author`, `excerpt`, the first `image` field, the first `markdown` field), so existing collections keep working.
- **The on-page editor, starter home page, and `cmsHead`.** These read the collection's declared roles: `titleField`, `bylineField`, `summaryField`, `imageField`, `bodyField`, and `dateField`. Nothing is guessed from field names (`author`, `excerpt`, `hero`, `publishedDate`, …) or from the first block. Declare the roles; `pnpm codemod explicit-roles <path-to-your-app>` (from a TanStack CMS checkout) sets them to what the old fallbacks picked.

### 12. AI, MCP, and Start are optional peers

Expand Down
2 changes: 1 addition & 1 deletion docs/schema/blocks-and-rendering.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ All built-ins are styled with the `--cms-*` theme tokens (see [Theming](./themin
| `richText` | `markdown` | GFM prose. |
| `image` | `image`, `caption` | Figure with caption. |
| `cta` | `heading`, `label`, `href` | Call-to-action panel with an accent button. |
| `callout` | `tone`, `title`, `markdown` (or `body`) | Bordered aside with a tone badge. |
| `callout` | `tone`, `title`, `markdown` | Bordered aside with a tone badge. |
| `code` | `code`, `language`, `filename` | Code panel with a filename/language header. |
| `columns` | `left`, `right` | Two responsive Markdown columns. |
| `embed` | `url`, `title`, `caption` | Link card for external content. |
Expand Down
6 changes: 4 additions & 2 deletions docs/schema/building-pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,10 @@ Package components build admin links with `adminPath('/content')`, which reads `
`cmsHead(doc, options)` returns `{ meta, links, scripts }` for a route's `head()`:

- `<title>` as `"<title> · <site name>"`, from the collection's `titleField`.
- `description`, from the collection's `summaryField`. Without a declared one: `excerpt`, `description`, `summary`, `subheading`, or the first block's `subheading`.
- OpenGraph and Twitter tags, with the image from the collection's `imageField`. Without a declared one: the first `image` field, `hero`, `image`, `coverImage`, `featuredImage`, `cover`, or the first block image. Root-relative images become absolute against `canonicalUrl`.
- `description`, from the collection's `summaryField`.
- OpenGraph and Twitter tags, with the image from the collection's `imageField` (default: its first `image` field). Root-relative images become absolute against `canonicalUrl`.

Nothing else stands in: a page built only from blocks has no description or image unless it declares a `summaryField`/`imageField` or fills its `seo` group.
- `<link rel="canonical">` and `og:url` from `canonicalUrl`.
- `noindex, nofollow` for unpublished documents (disable with `noIndexDrafts: false`) and for `seo.noindex`.
- A JSON-LD `<script>` with `jsonLd: true` (derived with `cmsJsonLd`) or `jsonLd: { … }` (used as-is).
Expand Down
10 changes: 5 additions & 5 deletions docs/schema/collections-and-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,17 @@ export const cms = defineCms({
| `slugField?` | `string` | Field used for slug lookups. Defaults to a field named `slug` (`getSlugField()`). |
| `blocksField?` | `string` | Field holding the page body. Defaults to the first `blocks` field (`getBlocksField()`). |
| `imageField?` | `string` | Featured image for thumbnails, the on-page editor, `cmsHead`, and JSON-LD. Defaults to the first `image` field (`getImageField()`). |
| `summaryField?` | `string` | Short summary for cards, meta descriptions, and the on-page editor. Defaults to a field named `excerpt`, `description`, `summary`, or `subheading` (`getSummaryField()`). |
| `bylineField?` | `string` | Author name for bylines and JSON-LD `author`. Defaults to a text field named `author` (`getBylineField()`). |
| `bodyField?` | `string` | Long-form body of a flat (non-block) document. Defaults to the first `markdown` field, then the first `richtext` field (`getBodyField()`). |
| `dateField?` | `string` | Publication date for JSON-LD `datePublished` (`getDateField()`). Without it, `cmsJsonLd` tries `publishedDate`, the scheduled `publishAt`, then `date`. |
| `summaryField?` | `string` | Short summary for cards, meta descriptions, and the on-page editor (`getSummaryField()`). No default. |
| `bylineField?` | `string` | Author name for bylines and JSON-LD `author` (`getBylineField()`). No default. |
| `bodyField?` | `string` | Long-form body of a flat (non-block) document. Defaults to the first `markdown` or `richtext` field that isn't the `summaryField` (`getBodyField()`). |
| `dateField?` | `string` | Publication date for JSON-LD `datePublished` (`getDateField()`). No default. |
| `schemaType?` | `string` | schema.org type for JSON-LD, e.g. `'BlogPosting'`. Article types also set `og:type` to `article`. Defaults to `'WebPage'`. |
| `migrations?` | `Array<ContentMigration>` | Data migrations for stored documents (see [Content migrations](#content-migrations)). |
| `access?` | `CollectionAccess` | Narrow who can `read`, `write`, `create`, `update`, `publish`, or `delete` (see [Access control](#access-control)). |
| `hooks?` | `CollectionHooks` | Lifecycle hooks (see [Hooks](#hooks)). |
| `admin?` | `{ columns?, defaultSort? }` | Admin list defaults. `columns` is the default set of extra columns after the title (editors can toggle them with the column picker); `defaultSort` is `{ field, dir? }` (default: most recently updated first). |

`imageField`, `summaryField`, `bylineField`, `bodyField`, and `dateField` are the collection's content **roles**: what post cards, the on-page editor, and `cmsHead` read. Declare them. A declared role is the only field `cmsHead` reads for it, even when that field is empty for a document. `getCollectionRoles(collection)` returns every role at once. The name-based defaults are going away: run `pnpm codemod explicit-roles <path-to-your-app>` from a TanStack CMS checkout to declare what they pick today.
`imageField`, `summaryField`, `bylineField`, `bodyField`, and `dateField` are the collection's content **roles**: what post cards, the on-page editor, and `cmsHead` read. Declare them. Nothing is guessed from field names: an undeclared summary, byline, or date is empty, and a block never stands in for a document field. The only defaults are single rules on field types: the first `image` field is the image, the first `markdown` or `richtext` field is the body, the first `blocks` field holds the blocks, and a field named `slug` is the slug. `getCollectionRoles(collection)` returns every role at once. To declare what the removed name-based fallbacks used to pick, run `pnpm codemod explicit-roles <path-to-your-app>` from a TanStack CMS checkout.

## Field types

Expand Down
62 changes: 15 additions & 47 deletions packages/core/src/lib/seo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import {
collections,
getBylineField,
getDateField,
getImageField,
getSummaryField,
isArticleSchemaType,
Expand Down Expand Up @@ -212,8 +213,7 @@ export function cmsJsonLd<TDoc extends object = Doc>(
const out: Record<string, unknown> = {
'@context': 'https://schema.org',
'@type': type,
[isArticle ? 'headline' : 'name']:
seo.title ?? (str(rec[titleField]) || str(rec.title)),
[isArticle ? 'headline' : 'name']: seo.title ?? str(rec[titleField]),
}
const description = seo.description ?? resolveDescription(rec, collection)
if (description) out.description = description
Expand All @@ -226,8 +226,7 @@ export function cmsJsonLd<TDoc extends object = Doc>(
if (published) out.datePublished = published
const modified = str(rec._updatedAt)
if (modified) out.dateModified = modified
const bylineField = collection ? getBylineField(collection) : 'author'
const author = bylineField ? str(rec[bylineField]) : ''
const author = roleValue(rec, collection && getBylineField(collection))
if (author && isArticle) out.author = { '@type': 'Person', name: author }
if (options?.siteName && isArticle) {
out.publisher = { '@type': 'Organization', name: options.siteName }
Expand Down Expand Up @@ -268,64 +267,33 @@ function resolveCollection(col?: string | Collection): Collection | undefined {
return col
}

/** The value of a collection role on a document, or `''`. */
function roleValue(
doc: Record<string, unknown>,
field: string | undefined,
): string {
return field ? str(doc[field]) : ''
}

function resolveDescription(
doc: Record<string, unknown>,
collection?: Collection,
): string {
if (collection?.summaryField) return str(doc[collection.summaryField])
const summaryField = collection ? getSummaryField(collection) : undefined
if (summaryField) {
const val = str(doc[summaryField])
if (val) return val
}
for (const key of ['excerpt', 'description', 'summary', 'subheading']) {
const val = str(doc[key])
if (val) return val
}
if (Array.isArray(doc.blocks)) {
for (const b of doc.blocks) {
if (b && typeof b === 'object' && !Array.isArray(b)) {
const sub = str((b as Record<string, unknown>).subheading)
if (sub) return sub
}
}
}
return ''
return roleValue(doc, collection && getSummaryField(collection))
}

function resolveImage(
doc: Record<string, unknown>,
collection?: Collection,
): string {
if (collection?.imageField) return str(doc[collection.imageField])
if (collection) {
const imgField = getImageField(collection)
if (imgField) {
const val = str(doc[imgField])
if (val) return val
}
}
for (const key of ['hero', 'image', 'coverImage', 'featuredImage', 'cover']) {
const val = str(doc[key])
if (val) return val
}
if (Array.isArray(doc.blocks)) {
for (const b of doc.blocks) {
if (b && typeof b === 'object' && !Array.isArray(b)) {
const img = str((b as Record<string, unknown>).image)
if (img) return img
}
}
}
return ''
return roleValue(doc, collection && getImageField(collection))
}

function resolveDate(
doc: Record<string, unknown>,
collection?: Collection,
): string {
if (collection?.dateField) return str(doc[collection.dateField])
return str(doc.publishedDate) || str(doc.publishAt) || str(doc.date)
return roleValue(doc, collection && getDateField(collection))
}

/**
Expand All @@ -349,7 +317,7 @@ export function cmsHead<TDoc extends object = Doc>(
const collection = resolveCollection(options?.collection)
const seo = seoOverrides(rec)
const titleField = collection?.titleField ?? 'title'
const rawDocTitle = rec ? str(rec[titleField]) || str(rec.title) : ''
const rawDocTitle = rec ? str(rec[titleField]) : ''
const pageTitle = options?.title ?? seo.title ?? rawDocTitle
const canonicalUrl = options?.canonicalUrl ?? seo.canonical
const fullTitle =
Expand Down
Loading
Loading