.agents/skills/sanity-config-reducers/SKILL.md
Use this skill when a config value can be supplied by root config or plugins and needs deterministic merge behavior.
Inspect these files first:
packages/sanity/src/core/config/types.tspackages/sanity/src/core/config/configPropertyReducers.tspackages/sanity/src/core/config/prepareConfig.tsxpackages/sanity/src/core/config/flattenConfig.tspackages/sanity/src/core/config/resolveDefaultPlugins.ts if the config gates default plugin injection.Reducers usually:
flattenConfig(config, []).initialValue.innerConfig.undefined.getPrintableType(value) for invalid values.Config namespaces should usually be objects, even when they initially only contain one flag. This keeps room for future options without changing the public shape. For booleans, prefer feature.enabled and follow this shape:
export const featureEnabledReducer = (opts: {
config: PluginOptions
initialValue: boolean
}): boolean => {
const {config, initialValue} = opts
const flattenedConfig = flattenConfig(config, [])
return flattenedConfig.reduce((acc, {config: innerConfig}) => {
const enabled = innerConfig.feature?.enabled
if (typeof enabled === 'undefined') return acc
if (typeof enabled === 'boolean') return enabled
throw new Error(
`Expected \`feature.enabled\` to be a boolean, but received ${getPrintableType(enabled)}`,
)
}, initialValue)
}
Root config is flattened after plugin config, so root values usually win when a reducer overwrites with the latest defined value.
When adding a config property:
PluginOptions, WorkspaceOptions, or the relevant nested type in types.ts.beta.feature.enabled over direct booleans such as beta.feature.Source, Workspace, or the relevant prepared object in prepareConfig.tsx.source.__internal.options as an implementation detail, not the primary runtime API.Default plugin lists are computed before full source resolution. If a config value controls default plugin injection:
prepareConfig.tsx, before calling getDefaultPlugins.getDefaultPluginsOptions or the options passed to getDefaultPlugins.Beta flags live under BetaFeatures in types.ts and resolved runtime values under source.beta.
Prefer a dedicated reducer when:
Do not special-case beta flags in components by reading raw config if a resolved value can be exposed instead.
Add focused config tests for:
enabled is not the documented type.