
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeI 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:
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';
}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')
}If this "suddenly" broke in production:
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 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.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store