portable-text-serialization
Render and serialize Portable Text to React, Svelte, Vue, Astro, HTML, Markdown, and plain text. Use when implementing Portable Text rendering in any frontend framework, building custom serializers for non-standard block types, converting Portable Text to HTML strings server-side, converting Portable Text to Markdown, extracting plain text from Portable Text, or troubleshooting rendering issues with marks, blocks, lists, or custom types.
Security Assessment
About portable-text-serialization
portable-text-serialization is a skill from the Sanity agent toolkit for rendering and serializing Portable Text — Sanity's JSON-based rich-text format — across many output targets: React, Svelte, Vue, Astro, HTML, Markdown, and plain text. It solves the recurring frontend problem of correctly turning Portable Text blocks, spans, marks, lists, and custom types into rendered output, which trips developers up because renderers only handle standard blocks by default and custom types silently fail to render without explicit component mappings.
The skill explains the Portable Text data structure (an array of blocks with _type, style, children spans, markDefs, listItem, and level, plus decorator and annotation marks) and the shared component-mapping pattern common to the @portabletext/* library family: a components object keyed by types, marks, block, list, listItem, and hardBreak. It routes to framework-specific rule files for React/Next.js, Svelte, Vue, Astro, HTML (server-side), Markdown, and plain-text extraction, each naming the appropriate package such as @portabletext/react, astro-portabletext, or @portabletext/to-html, and lists additional community serializers for React Native, PDF, Solid, Qwik, Shopify Liquid, PHP, Python, .NET, and Flutter. It also documents cross-framework best practices: giving custom types explicit components, keeping the components object stable (defined outside render or memoized) to avoid re-renders, handling missing components with onMissingComponent, and expanding references in GROQ queries so images and internal links resolve.
It targets frontend and full-stack developers building Sanity-backed sites who need to render Portable Text in a specific framework, build custom serializers for non-standard blocks, or convert content to HTML, Markdown, or plain text. It is educational reference documentation with example rendering code and no risky behavior.
FAQ
Which output targets does it cover?
React/Next.js, Svelte, Vue, Astro, server-side HTML, Markdown, and plain-text extraction have dedicated rule files, and it lists additional community serializers for React Native, React PDF, Solid, Qwik, Shopify Liquid, PHP, Python, C#/.NET, and Dart/Flutter.
What is the common rendering pattern?
Every @portabletext/* library accepts a components object mapping node types via the keys types (custom blocks/inline), marks (decorators and annotations), block (styles like h1/blockquote), list, listItem, and hardBreak to framework-specific renderers.
Why aren't my custom blocks rendering?
PT renderers only handle standard blocks by default. Custom types such as image, code, or callToAction require explicit component mappings; without them they won't render. The libraries also accept onMissingComponent to control behavior for unknown types.
Any performance advice?
In React and Vue, define the components object outside the render function or memoize it, because recreating it on every render causes unnecessary re-renders.
How should I query Portable Text with GROQ?
Always expand references inside custom blocks — for example dereferencing image assets and resolving internal-link slugs in markDefs — so that images and internal links have the data they need to render.
Install portable-text-serialization
Quick Setup:
- Copy the skill folder to
.claude/skills/ - Claude will automatically detect and use the skill
Repository
sanity-io/agent-toolkit