Rich Text Blocks Validation#
Overview#
Strapi's Blocks rich-text field uses two independent layers of validation: a client-side block store (admin) and a server-side yup validator. When a plugin registers a custom node type through the admin API, that type is accepted by the editor but unconditionally rejected by the server when the entry is saved or published. This is the primary source of confusion for plugin authors extending the Blocks editor.
Server-Side Validator: Fixed Node Type Allowlist#
The authoritative server validator lives in blocks-validator.ts. It exports blocksValidator(), which returns a yup array schema that dispatches on each node's type field via blockNodeValidator ā a lazy yup schema with a hard-coded switch statement :
Accepted block type | Validator |
|---|---|
paragraph | paragraphNodeValidator |
heading | headingNodeValidator |
quote | quoteNodeValidator |
list | listNodeValidator |
image | imageNodeValidator |
code | codeBlockValidator |
Any unrecognized type value hits the default branch, which always returns false with the message "Block node is of invalid type" . There is no extension point in blockNodeValidator ā it cannot be modified by plugins at runtime.
blocksValidator is registered in the entity-validator's Validators map under the blocks attribute type , so it runs for every blocks field on every save/publish operation.
Inline nodes follow the same pattern: inlineNodeValidator accepts only text and link; anything else fails validation .
Client-Side Extension API: addRichTextBlocks#
The admin exposes addRichTextBlocks on the ContentManagerPlugin class in content-manager.ts. It accepts either a plain RichTextBlocksStore object (merged via spread) or a reducer function . The store starts from defaultBlocksStore, which includes the seven built-in block definitions .
Registered blocks are read by getRichTextBlocks() and used by BlocksEditor to render custom block types and apply their Slate plugins. This is purely a client-side rendering concern ā the API has no server counterpart.
The Mismatch#
Plugin calls addRichTextBlocks({ "my-block": ... })
ā
Admin editor renders "my-block" nodes correctly
ā
On save/publish ā entity-validator runs blocksValidator
ā
blockNodeValidator default branch: "Block node is of invalid type" ā
Any node with a type not in the six built-in block types will be rejected server-side, even if it renders correctly in the editor. This is a structural gap: the client-side store is dynamic and plugin-extensible, while the server-side validator is a static, closed enum with no plugin extension mechanism.
Key Files#
| File | Purpose |
|---|---|
entity-validator/blocks-validator.ts | Server-side yup schema; defines the closed set of valid block node types |
entity-validator/validators.ts | Registers blocksValidator for the blocks attribute type |
content-manager/admin/src/content-manager.ts | addRichTextBlocks / getRichTextBlocks admin API |
BlocksInput/DefaultBlocksStore.tsx | Default block store (paragraph, heading, list, link, image, quote, code) |
Workarounds#
Because the server validator has no extension API, options are limited:
- Map custom nodes to built-in types before saving. A plugin can transform custom nodes into a built-in representation (e.g., wrap content in a
paragraphwith metadata stored in a separate field) before the save API call, then reverse the transformation when loading. - Use a separate field. Store structured data that needs custom node types in a
jsonfield, which has no structural validation , alongside ablocksfield. - Replace the entire editor. The documented Strapi approach for fully custom editor requirements is a custom WYSIWYG field plugin, which bypasses the Blocks field and its validator entirely.
A server-side extension mechanism for blocksValidator would require changes to blockNodeValidator and the plugin registration pipeline in Strapi core ā there is no such mechanism at the time of writing.
Related#
- Blocks Editor URL Validation ā separate mismatch between client-side link validation and server-side
checkValidLink, including the fragment-URL (#anchor) regression bug.