portable-text-serialization

द्वारा sanity-io

पोर्टेबल टेक्स्ट को React, Svelte, Vue, Astro, HTML, Markdown और सादे टेक्स्ट में रेंडर और सीरियलाइज़ करें। किसी भी फ्रंटएंड में पोर्टेबल टेक्स्ट रेंडरिंग लागू करते समय उपयोग करें…

npx skills add https://github.com/sanity-io/agent-toolkit --skill portable-text-serialization

Portable Text Serialization

Render Portable Text content across frameworks using the @portabletext/* library family. Each library follows the same component-mapping pattern: you provide a components object that maps PT node types to framework-specific renderers.

Portable Text Structure (Quick Reference)

PT is an array of blocks. Each block has _type, optional style, children (spans), markDefs, listItem, and level.

Root array
├── block (_type: "block")
│   ├── style: "normal" | "h1" | "h2" | "blockquote" | ...
│   ├── children: [span, span, ...]
│   │   └── span: { _type: "span", text: "...", marks: ["strong", "<markDefKey>"] }
│   ├── markDefs: [{ _key, _type: "link", href: "..." }, ...]
│   ├── listItem: "bullet" | "number" (optional)
│   └── level: 1, 2, 3... (optional, for nested lists)
├── custom block (_type: "image" | "code" | any custom type)
└── ...more blocks

Marks come in two forms:

  • Decorators: string values in marks[] like "strong", "em", "underline", "code"
  • Annotations: keys in marks[] referencing entries in markDefs[] (e.g., links, internal references)

Component Mapping Pattern (All Frameworks)

Every @portabletext/* library accepts a components object with these keys:

KeyRendersProps/Data
typesCustom block/inline types (image, code, CTA)value (the block data)
marksDecorators + annotationschildren + value (mark data)
blockBlock styles (h1, normal, blockquote)children
listList wrappers (ul, ol)children
listItemList itemschildren
hardBreakLine breaks within a block

Framework-Specific Rules

Read the rule file matching your framework:

  • React / Next.js: rules/react.md@portabletext/react or next-sanity
  • Svelte / SvelteKit: rules/svelte.md@portabletext/svelte
  • Vue / Nuxt: rules/vue.md@portabletext/vue
  • Astro: rules/astro.mdastro-portabletext
  • HTML (server-side): rules/html.md@portabletext/to-html
  • Markdown: rules/markdown.md@portabletext/markdown
  • Plain text extraction: rules/plain-text.md@portabletext/toolkit

Additional Community Serializers

These are listed on portabletext.org but don't have dedicated rule files:

TargetPackage
React Native@portabletext/react-native-portabletext
React PDF@portabletext/react-pdf-portabletext
Solidsolid-portabletext
Qwikportabletext-qwik
Shopify Liquidportable-text-to-liquid
PHPsanity-php (SanityBlockContent class)
Pythonportabletext-html
C# / .NETdotnet-portable-text
Dart / Flutterflutter_sanity_portable_text

Common Patterns (All Frameworks)

Custom Types Need Explicit Components

PT renderers only handle standard blocks by default. Custom types (image, code, callToAction, etc.) require explicit component mappings — they won't render otherwise.

Keep Components Object Stable

In React/Vue, define components outside the render function or memoize it. Recreating on every render causes unnecessary re-renders.

Handle Missing Components Gracefully

All libraries accept onMissingComponent to control behavior when encountering unknown types:

  • false — suppress warnings
  • Custom function — log or report

Querying PT with GROQ

Always expand references inside custom blocks:

body[]{
  ...,
  _type == "image" => {
    ...,
    asset->
  },
  markDefs[]{
    ...,
    _type == "internalLink" => {
      ...,
      "slug": @.reference->slug.current
    }
  }
}

sanity-io की और Skills

performance-optimization
sanity-io
एप्लिकेशन के प्रदर्शन को अनुकूलित करता है। इसका उपयोग तब करें जब प्रदर्शन आवश्यकताएं हों, जब आपको प्रदर्शन में गिरावट का संदेह हो, या जब कोर वेब वाइटल्स या लोड समय...
official
rxjs-like-a-pro
sanity-io
यह कौशल आपको ऐसा RxJS कोड लिखने में मदद करता है जो स्वाभाविक, संयोजनीय और सामान्य कमियों से मुक्त हो। मुख्य दर्शन: तर्क को ऑब्ज़र्वेबल श्रृंखला में रखें। जब भी आप .subscribe() का उपयोग करने जाएं, तो पूछें कि क्या वह कार्य .pipe() के अंदर एक रूपांतरण के रूप में व्यक्त किया जा सकता है।
official
find-skills
sanity-io
उपयोगकर्ताओं को एजेंट कौशल खोजने और स्थापित करने में मदद करता है जब वे ऐसे प्रश्न पूछते हैं जैसे "मैं X कैसे करूं", "X के लिए कोई कौशल खोजें", "क्या कोई ऐसा कौशल है जो...", या व्यक्त करते हैं...
official
next-cache-components
sanity-io
Next.js 16 कैश घटक - PPR, use cache निर्देश, cacheLife, cacheTag, updateTag
official
vercel-react-best-practices
sanity-io
React और Next.js प्रदर्शन अनुकूलन दिशानिर्देश Vercel Engineering से। इस कौशल का उपयोग React/Next.js को लिखने, समीक्षा करने या रीफैक्टर करते समय किया जाना चाहिए…
official
frontend-design
sanity-io
उच्च डिज़ाइन गुणवत्ता के साथ विशिष्ट, उत्पादन-स्तर के फ्रंटएंड इंटरफ़ेस बनाएं। इस कौशल का उपयोग तब करें जब उपयोगकर्ता वेब घटकों, पृष्ठों या... बनाने के लिए कहे।
official
plugin-transfer
sanity-io
एजेंटों को कॉपी-प्लगइन जनरेटर वर्कफ़्लो के साथ मौजूदा प्लगइन को इस मोनोरिपो में स्थानांतरित करने का मार्गदर्शन देता है।
official
test-studio-script-runner
sanity-io
dev/test-studio स्क्रिप्ट रनर टूल की व्याख्या करता है। इसका उपयोग तब करें जब dev/test-studio/src/script-runner में स्क्रिप्ट जोड़ना, संपादित करना, चलाना या दस्तावेज़ीकरण करना हो, या जब...
official