Skip to main content

Build

Sanity Form Component Suspense

SanityOfficialCertified

Fix a Sanity Studio custom form component (components.input, components.field, components.item, or a plugin's form.components) that suspends without its own Suspense boundary, so it loads without layout shift and never blocks new documents. Use when the console warns "The custom input/field/item component ... suspended without a <Suspense> boundary of its own" or "A form component ... suspended without a <Suspense> boundary of its own", when a custom form component uses React.lazy, use(), App SDK hooks (useDocumentProjection, useQuery, useDocument) or another suspending data library, or when a field or array item shows a skeleton that never goes away on new documents.

  • New
  • v1.0.0
  • Reviewed Oct 22
  • No reviews yet

Getting started

Full instructions

Install the skill, then ask your AI tool for the task in plain words. The full SKILL.md below shows what it covers.

Instructions: SKILL.mdv1.0.0

Custom form components that suspend

Studio puts a fallback boundary around every field and every array item, so one suspending
component cannot blank the form. That fallback is a generic skeleton: it does not know the size of
what it replaces, so the form shifts when the component loads, and Studio warns about it in the
console. The fix always lives in your code: declare a Suspense around the part that suspends,
with a fallback that takes the same space as what it stands in for. Any boundary you declare is
closer to what suspends than Studio's, so it always wins and nothing warns. That includes a
boundary in a custom field around props.renderDefault(props), which also covers the field's
input: use it when one fallback should cover both, for example a lazy input that also fetches.

Workflow

  1. Find the component. The warning names the custom components declared for that field or
    item (components.field, .input or .item), the path, the document type and the schema type,
    and logs the components themselves; click one in the browser console to open its source.
    Production builds minify the names, so use the path and document type there. When the schema
    type declares none, the warning starts with "A form component" and the culprit is usually a
    plugin's form.components. React DevTools' Suspense tab shows which component actually
    suspended.
  2. Find what suspends. Usually one of: React.lazy, use(promise), an App SDK hook
    (useDocumentProjection, useDocument, useQuery, useDocuments), or a library in suspense
    mode (useSuspenseQuery).
  3. Move it into its own component if it is not already, and wrap only that component in
    <Suspense> inside the custom component. Keep props.renderDefault(props) outside the
    boundary, so the built-in input, field or item never unmounts (and never loses focus while
    someone types) when the async part suspends again.
  4. Reserve the space. The fallback must have the size of the loaded UI:
    • Additive UI (warnings, previews, counts): render it after renderDefault so it never pushes
      the rest down, and give the fallback the height of one loaded row.
    • A whole component that loads lazily: a skeleton with the component's height, not null.
    • Array items: the list is virtualized and measures each row, so an item fallback that is
      shorter or taller than the loaded row makes the rows below it jump. Match the row height.
  5. Do not suspend on a document that does not exist yet. A new document only exists once the
    first edit creates it, and SDK hooks that read the current document wait for it forever. Gate
    on useFormValue(['_createdAt']): it is unset until the document exists.
  6. Keep promises stable. A promise created during render, in useState or in useMemo is
    thrown away while the component suspends on mount, so use() gets a new one every retry and
    never settles. Use the SDK hooks, a module-scope cache keyed by the inputs, or a data library.
  7. Verify. Open a new document of the type and an existing one: the warning is gone, the rest
    of the form is editable right away, and nothing moves when the async part lands.

Example

tsx
import {createDocumentHandle, useDocumentProjection} from '@sanity/sdk-react'
import {Card, Skeleton, Stack, Text} from '@sanity/ui'
import {Suspense} from 'react'
import {type ArrayOfObjectsInputProps, getPublishedId, useFormValue} from 'sanity'

export function ModelSizeInput(props: ArrayOfObjectsInputProps) {
  const documentId = useFormValue(['_id']) as string
  const documentExists = Boolean(useFormValue(['_createdAt']))
  const hasModels = (props.value?.length ?? 0) > 0

  return (
    <Stack gap={3}>
      {props.renderDefault(props)}
      {documentExists && hasModels ? (
        <Suspense fallback={<Skeleton radius={2} style={{height: 33}} animated />}>
          <ModelSizeWarnings documentId={getPublishedId(documentId)} />
        </Suspense>
      ) : null}
    </Stack>
  )
}

function ModelSizeWarnings(props: {documentId: string}) {
  const {data} = useDocumentProjection<{missing: number}>({
    ...createDocumentHandle({documentType: 'product', documentId: props.documentId}),
    projection: `{"missing": count(models[!defined(@->size)])}`,
  })
  return (
    <Card padding={2} radius={2} tone={data.missing > 0 ? 'critical' : 'positive'}>
      <Text size={1}>{data.missing} models are missing a size</Text>
    </Card>
  )
}

The skeleton's height matches the one-line card it stands in for. If the loaded UI's height
varies, reserve the most common case and keep the variable part below the input.

Explore more skills

Browse all
This skill doesn’t include stateful context yet, instructions only. Learn about stateful skills.

Security

Loading security scan...

Reviews (0)

More from Sanity

View source →
sanity-best-practicesSanity development best practices for schema design, GROQ queries, TypeGen, Visual Editing, images, Portable Text, Studio structure, localization, migrations, Sanity Functions, webhooks, Blueprints, and framework integrations such as…1 installscontent-experimentation-best-practicesContent experimentation and A/B testing guidance covering experiment design, hypotheses, metrics, sample size, statistical foundations, CMS-managed variants, and common analysis pitfalls. Use this skill when planning experiments, setting…0 installsportable-text-conversionConvert HTML and Markdown content into Portable Text blocks for Sanity. Use when migrating content from legacy CMSs, importing HTML or Markdown into Sanity, building content pipelines that ingest external content, converting rich text…0 installsportable-text-serializationRender 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…0 installsseo-aeo-best-practicesSEO and AEO best practices for metadata, Open Graph, sitemaps, robots.txt, hreflang, JSON-LD structured data, EEAT, and content optimized for search engines and AI answer surfaces. Use this skill when implementing page SEO, technical SEO,…0 installscontent-modeling-best-practicesStructured content modeling guidance for schema design, content architecture, content reuse, references versus embedded objects, separation of concerns, and taxonomies across Sanity and other headless CMSes. Use this skill when designing…0 installs

Frequently asked questions about sanity-form-component-suspense

What does the sanity-form-component-suspense skill do?

Fix a Sanity Studio custom form component (components.input, components.field, components.item, or a plugin's form.components) that suspends without its own Suspense boundary, so it loads without layout shift and never blocks new documents. Use when the console warns "The custom input/field/item component ... suspended without a <Suspense> boundary of its own" or "A form component ... suspended without a <Suspense> boundary of its own", when a custom form component uses React.lazy, use(), App SDK hooks (useDocumentProjection, useQuery, useDocument) or another suspending data library, or when a field or array item shows a skeleton that never goes away on new documents. It's a reusable SKILL.md instruction set that loads into your AI coding assistant on demand, no prompt engineering, no copy-pasting every session.

How do I install the sanity-form-component-suspense skill?

Run `npx @skills-hub-ai/cli install sanity-form-component-suspense` from your terminal. The CLI writes the SKILL.md to the correct location for your AI tool (e.g. ~/.claude/skills/sanity-form-component-suspense/ for Claude Code or ~/.cursor/skills/ for Cursor with --target cursor) and adds it to your project's .skills.json lockfile.

Which AI tools does sanity-form-component-suspense work with?

sanity-form-component-suspense runs in Claude Code. It follows the open Agent Skills standard (SKILL.md), so the same skill works in every supported tool without modification.

Is the sanity-form-component-suspense skill free?

Yes. Every skill on skills-hub.ai is free and open-source. There are no premium tiers, paywalls, or usage limits. You only pay for whatever AI assistant you're already using.

How do I use sanity-form-component-suspense after installing it?

In Claude Code, type `/sanity-form-component-suspense` (or whatever slash command the skill registers) and the AI follows the skill's instructions immediately. You can also reference it by name in natural language, your AI loads the skill into context when relevant.

Can I share the sanity-form-component-suspense skill with my team?

Yes. Commit your project's .skills.json lockfile and teammates run `npx @skills-hub-ai/cli install` (no args) to install every skill at the exact version you pinned. Organization-scoped installs work via skills-hub.ai organizations.

Badge for your README

Show that this skill is on Skills Hub. The badge links back to this page and shows the live install count.

Install on Skills Hub badge preview
Markdown
[![Install on Skills Hub](https://skills-hub.ai/api/badges/skill/sanity-form-component-suspense)](https://skills-hub.ai/skills/sanity-form-component-suspense)
HTML
<a href="https://skills-hub.ai/skills/sanity-form-component-suspense"><img src="https://skills-hub.ai/api/badges/skill/sanity-form-component-suspense" alt="Install on Skills Hub"></a>

More options in the badge docs.