Skip to main content
skill CX Codex

sanity-form-component-suspense — Claude Code skill guide

sanity-form-component-suspense — a skill for Claude Code that fixes Sanity Studio custom form components suspending without explicit boundaries. Eliminates layout shifts from React.lazy and App SDK hooks.

MIT 271 installs ★ 201 updated 2026-10-23

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add sanity-io/agent-toolkit --skill sanity-form-component-suspense -a claude-code
Open on GitHub

What sanity-form-component-suspense does

This skill locates custom inputs, fields, and array items in Sanity Studio that trigger suspense without a local boundary. Studio wraps fields in generic fallback skeletons by default, causing visible layout jumps and console warnings upon load.

The workflow separates suspending logic—like use(), React.lazy, or useDocumentProjection—into an isolated component wrapped in <Suspense>. It keeps props.renderDefault outside the boundary to prevent input unmounting and focus loss during typing.

Because App SDK hooks wait indefinitely on unsaved documents, the skill gates loading on useFormValue(['_createdAt']). The component will freeze in an endless loading state on blank records if this check is omitted.

What it helps with

  • eliminate Sanity Studio console warnings about unhandled suspense
  • prevent UI layout shifts during lazy component loading
  • preserve form input focus when asynchronous queries refresh
  • resolve permanent skeleton loaders on unsaved studio documents

Example prompts for the agent

  • Add a Suspense boundary to the lazy selector in schema/product.ts
  • Fix the Sanity Studio warning about an unhandled suspending form component
  • Stop the custom array item from shifting the layout when it loads

How to install sanity-form-component-suspense

1Skills CLI (Vercel)

npx skills add sanity-io/agent-toolkit --skill sanity-form-component-suspense -a claude-code

2Manually: put the files in place

~/.claude/skills/sanity-form-component-suspense/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/sanity-form-component-suspense/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about sanity-form-component-suspense

How to install sanity-form-component-suspense in Claude Code?

Run npx skills add sanity-io/agent-toolkit --skill sanity-form-component-suspense -a claude-code.

What does sanity-form-component-suspense do?

It isolates suspending custom components in Sanity Studio forms with local boundaries and matched skeleton fallbacks.

What is required for sanity-form-component-suspense to work?

A Sanity Studio project using custom form inputs, fields, or array items with React suspense hooks or lazy loading.

Source text

SKILL.md · MIT
---
name: sanity-form-component-suspense
description: 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.
---

# 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.

© sanity-io · MIT · sanity-io/agent-toolkit

Similar skills

All skills for Frontend and UI →

From the same set12

The whole set →
content-modeling-best-practices content-modeling-best-practices guides your agent through content type design in headless CMS: what to reference, what to embed, how to stop duplicating data. CX Codex +1 5,200installs content-experimentation-best-practices The content-experimentation-best-practices skill guides content A/B test planning, metric selection, and result analysis. Use it when working with CMS-managed variants or frontend experiments. CX Codex +1 4,100installs portable-text-serialization portable-text-serialization — a skill that shows the agent how to render and serialize Portable Text to React, Svelte, Vue, Astro, HTML, Markdown and plain text. CX Codex +1 3,100installs portable-text-conversion portable-text-conversion turns HTML and Markdown into Portable Text blocks for Sanity. Useful when migrating content off a legacy CMS or building an import pipeline. CX Codex +1 3,000installs sanity-studio-upgrade The sanity-studio-upgrade skill inspects your repo and reports only the breaking changes that actually apply to it. Handy when your Studio sits several majors behind. CX Codex +1 827installs sanity-singletons sanity-singletons is a Claude Code skill for configuring singleton documents in Sanity Studio. It applies when setting up fixed-ID content or replacing a third-party singleton plugin. CX Codex +1 392installs Sanity Connects your agent to a Sanity project: content, datasets, releases and schemas. Useful when CMS edits happen in chat instead of Studio. CX Codex +1 ★ 201repo stars sanity Connects Claude Code to Sanity workspaces with an MCP server, best-practice skills for content modeling, and GROQ helpers. ★ 201repo stars

Project sponsors

Companies that keep this analytics open