Issue with the `hidden` property returning undefined for the `parent` prop in a fieldset in Sanity Studio.
I understand this is urgent! The parent prop being undefined in your hidden callback is a critical issue. Here are the most likely causes and solutions:
Most Common Causes
1. Nested Field Structure Issue
The parent prop refers to the immediate parent object containing your field. If your field is at the document root level (not nested in an object or array), parent will be undefined. Check if your field structure changed:
// If field is at root level, parent is undefined
{
name: 'myField',
type: 'string',
hidden: ({parent}) => parent?.someValue // parent is undefined here!
}
// Parent only exists when field is inside an object/array
{
name: 'myObject',
type: 'object',
fields: [
{
name: 'myField',
type: 'string',
hidden: ({parent}) => parent?.someValue // parent = myObject
}
]
}2. Use document Instead
If you need to reference other fields at the document level, use the document parameter instead of parent:
{
name: 'conditionalField',
type: 'string',
hidden: ({document}) => document?.someOtherField !== 'value'
}3. Safe Access Pattern
Always use optional chaining to prevent errors when parent might be undefined:
hidden: ({parent, document}) => {
// Defensive check
if (!parent) return false; // or true, depending on your logic
return parent.someField !== 'expectedValue';
}Immediate Fix
Try this pattern from the conditional fields documentation:
hidden: ({parent, document, value}) => {
// Use document for root-level field references
// Use parent only when field is nested
return !(parent?.fieldName === 'value' || document?.rootField === 'value')
}Check Recent Changes
If this "suddenly" broke in production:
- Did you recently deploy schema changes that moved fields from nested objects to the root level?
- Did you update Sanity Studio versions? (Though this isn't a known breaking change in v3 or v4)
- Check if the parent object/array structure was modified
Debug Strategy
Add temporary logging to understand what's happening:
hidden: ({parent, document, value}) => {
console.log('Debug:', { parent, document, value });
// Your condition here
}The key insight: parent only exists when your field is nested inside an object or array type. For document-level fields, you must use the document parameter instead. As shown in the conditional fields guide, the callback receives {parent, document, value, currentUser} - use the appropriate one based on your field's location in the schema.
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.