sanity-config-reducers

Implements config property reducers that merge Sanity root config and plugin options deterministically.

6.3k|550|Updated Jan 18, 2017
One-click install
npx skills add https://github.com/sanity-io/sanity --skill sanity-config-reducers
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sanity-config-reducers
Source: https://github.com/sanity-io/sanity/tree/main/.agents/skills/sanity-config-reducers
Command: npx skills add https://github.com/sanity-io/sanity --skill sanity-config-reducers

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

When a Sanity config value can be supplied by both root config and plugins, it needs deterministic merge behavior. This Skill guides adding and reviewing config property reducers in packages/sanity/src/core/config so values resolve consistently across sources.

Core Features & Use Cases

  • Reducer Pattern Guidance: Standardizes reducers that flatten config, reduce from an explicit initial value, ignore undefined entries, and throw typed errors for invalid values.
  • Beta Flags and Default Plugin Gates: Covers adding beta flags under BetaFeatures and gating default plugin injection with reduced values computed early in prepareConfig.
  • Type Exposure: Explains declaring input types in PluginOptions or WorkspaceOptions and exposing resolved values on Source or Workspace.
  • Use Case: When adding a new feature flag like beta.feature.enabled that plugins can override, use this Skill to write the reducer, wire it into prepareConfig, and add tests for defaults, precedence, and invalid values.

Quick Start

Ask the assistant to add a new reduced Sanity config property, such as a beta feature flag, following the reducer pattern in packages/sanity/src/core/config.

Frequently Asked Questions about sanity-config-reducers

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

FAQPage Schema
How do I add a new config property to Sanity that plugins can override?

Declare the input type in PluginOptions or WorkspaceOptions in types.ts, then write a reducer in configPropertyReducers.ts that flattens config and reduces from an explicit initial value. Expose the resolved value on Source or Workspace in prepareConfig.tsx.

How do Sanity config reducers merge root config and plugin config?

Reducers call flattenConfig and reduce over each inner config, ignoring undefined values and accepting only the documented type. Root config is flattened after plugin config, so root values win when the reducer overwrites with the latest defined value.

Should a Sanity feature flag be a boolean or an object namespace?

Prefer extensible object namespaces such as beta.feature.enabled over direct booleans. Object namespaces leave room for future options without changing the public config shape.

How do I gate default plugin injection on a config value in Sanity?

Compute the reduced value early in prepareConfig.tsx before calling getDefaultPlugins, then thread it into getDefaultPluginsOptions. Reuse the same reducer when exposing the resolved runtime value so gating and runtime context agree.

What tests should I add for a new Sanity config reducer?

Add focused config tests covering the default value, root config value, plugin-provided value, root-over-plugin precedence, and error messages for invalid namespace objects and invalid nested property types.