sanity-best-practices

Provides Sanity development best practices for schemas, GROQ queries, TypeGen, and framework integrations.

1|Updated Mar 26, 2026
One-click install
npx skills add https://github.com/arndvs/ctrlshft --skill sanity-best-practices-arndvs
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: sanity-best-practices
Source: https://github.com/arndvs/ctrlshft/tree/main/skills/sanity-best-practices
Command: npx skills add https://github.com/arndvs/ctrlshft --skill sanity-best-practices-arndvs

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Developers working with Sanity often write slow GROQ queries, poorly structured schemas, or incorrect framework integrations because best practices are scattered across documentation. This Skill consolidates Sanity-maintained guidance into topic-specific references and atomic rules that load only what the current task needs. ## Core Features & Use Cases - GROQ Performance Rules: Atomic rules covering optimizable filters, cursor-based pagination, reference merging, and projection discipline to keep queries fast on large datasets. - Framework Integration Guides: Step-by-step integration patterns for Next.js, Nuxt, Astro, Remix, SvelteKit, Angular, Hydrogen, and the Sanity App SDK, including data fetching, Portable Text rendering, and image optimization. - Platform Feature Coverage: Guidance for Sanity Functions, Blueprints infrastructure-as-code, Visual Editing, TypeGen, localization, migrations, and Studio structure. - Use Case: While building a Next.js blog backed by Sanity, the agent loads the nextjs and groq references to set up defineLive, wrap queries in defineQuery for TypeGen, and avoid non-optimizable filters before writing any code. ## Quick Start Ask the agent to review your Sanity schema design or GROQ query using the Sanity best practices skill before implementing changes.

Frequently Asked Questions about sanity-best-practices

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I optimize slow GROQ queries in Sanity?▼

Stack optimizable filters like _type and defined() first so indexes reduce the search space, use _ref instead of -> in filters, and always project only needed fields. For deep pagination, use cursor-based queries with _id rather than large slice offsets.

How to integrate Sanity with Next.js App Router?▼

Use defineLive from next-sanity/live and fetch data via sanityFetch instead of scattering raw client.fetch calls. Wrap queries in defineQuery so TypeGen generates result types automatically, and configure the Presentation tool for Visual Editing.

Does Sanity Visual Editing work with Angular?▼

Angular has no official Visual Editing support — there is no Stega encoding or click-to-edit overlay integration. You can build a basic preview mode with a token-authenticated client using the drafts perspective, kept server-side only.

What is Sanity TypeGen and how do I set it up?▼

TypeGen generates TypeScript types from your schema and GROQ queries. Enable it in sanity.cli.ts with a path glob and output file, wrap queries in defineQuery, and types regenerate during sanity dev or via npm run typegen.

When should I use Sanity Functions versus webhooks?▼

Use Sanity Functions when you need to read or mutate document data in response to content events, such as setting computed fields or calling Agent Actions. Use a plain webhook when you only need to notify an external URL on publish without data shaping.

Why does my Sanity Function keep re-triggering itself?▼

The function mutates the same document type it listens to, creating an infinite loop. Add a GROQ filter that excludes already-processed documents, such as !defined(firstPublished), and use @sanity/client v7.12.0+ for automatic lineage-based recursion protection.