AddThisFeature

Sanity Document Publishing

Publish app content into Sanity as valid documents and assets, respecting draft workflows.

involved Integrations

What it adds

A publishing path that creates and updates Sanity documents and their assets from app records, honouring the target schema and draft pairing.

What your agent is told to do

5
  1. 1

    Derive each document's identifier deterministically from the app record it represents, so a retried or repeated publish updates the same document rather than scattering near-identical copies through the dataset.

  2. 2

    Read the target schema and validate the payload against it before sending, rejecting the write locally with a readable error rather than discovering the mismatch as a rejected mutation in a background job.

  3. 3

    Upload every image and file asset first, wait for the asset to be usable, and only then write the document that references it.

  4. 4

    Handle the draft and published pair explicitly: decide whether the app writes drafts for a human to publish or publishes directly, prefer writing drafts, and never let a routine sync publish something an editor deliberately left in draft.

  5. 5

    Do not pass user-authored rich text or references straight through into the document body. Constrain it to the block types, marks, and reference targets the schema allows, because an unconstrained body is a way for one user's input to reach every reader of the published site.

Edge cases it handles

8
  • Identifiers must be stable and derived from the source record. Letting the destination assign one, or generating a fresh one per run, produces silent duplicates that are only noticed once the site shows the same item twice.
  • A payload that does not match the schema will be rejected wholesale. Validate before sending so the failure is attributable to a named field rather than an opaque mutation error.
  • Assets are processed asynchronously. A document written immediately after an upload can reference an asset that is not yet ready, producing a broken image on a page that was reported as published successfully.
  • Draft and published documents exist as a pair. Writing to the wrong half either publishes unreviewed content or leaves the app's changes invisible on the live site with nothing to indicate why.
  • Portable text and reference fields must be constrained to what the schema permits. Arbitrary block types or references pointing at unexpected documents will either fail validation or render as something nobody designed.
  • Multiple mutations belonging to one logical publish should be sent as a single transaction where the destination allows it, so a failure part way through does not leave a document referencing assets that were never linked.
  • Rate limits and outages need bounded retries with backoff, and a publish that could not be delivered must be visible in the app as pending rather than reported as done.
  • The stored token can be revoked at any time. Distinguish an authentication failure from a transient error, stop retrying, and prompt an operator to reconnect.

Definition of done

9
  • Document identifiers are deterministic, so repeat publishes update rather than duplicate.
  • Payloads are validated against the target schema before any write is attempted.
  • Assets are uploaded and confirmed usable before the documents that reference them are written.
  • Draft and published documents are handled as a pair, with the app defaulting to writing drafts.
  • User-supplied rich text and references cannot introduce structures the schema does not allow.
  • A failed publish leaves no half-written document and is shown in the app as pending, not complete.
  • A revoked token stops retries and surfaces a reconnect prompt.
  • The feature matches the existing design system.
  • No existing functionality is broken.

Related features

How it works

  1. 1

    Copy the link

    Grab the Markdown instruction URL for this feature.

  2. 2

    Give it to your AI

    Paste it into Claude Code, Cursor, v0, Lovable — whatever you build with.

  3. 3

    It inspects, then implements

    Your agent reads your existing app first, then adds the feature to fit it.

Works with your stack

These instructions are written to adapt. They tell the agent to detect your framework, match your existing design system, and reuse what you already have — rather than assuming a particular stack.

Need it tighter than that? Customize the feature and tell it exactly what you're running.