Issue with the `hidden` property returning undefined for the `parent` prop in a fieldset in Sanity Studio.

38 replies
Last updated: Jun 6, 2023
URGENT: Our
parent
prop being returned from
hidden
is totally
undefined
all of a sudden on production...
AI Update

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.

This is happening everywhere in our schema, out of nowhere on production builds of a client studio.
No idea what is going on, but this is 1000% not a user error. Did something change with what data is returned in the
hidden
property for fields in V3?
Can confirm this is a field in an object... this should absolutely be coming through with data according to the docs
yet, it looks like the
value
prop is now taking the ENTIRE object value, not the actual field value?
For context: this is for the
graphicAspectRatio
field, so the
value
property SHOULD only equal
"custom"
, but instead it's getting the entire parent object's field values, and
parent
is undefined.
Again, no changes were made on our end, the client just started reporting the studio crashing (since I wasn't optionally chaining the
parent.[field]
). We're on the latest version of v3 btw!
user A
/
user M
any chance you know what's up? I've never seen this before☝️
Please don’t tag team members that aren’t already involved in a thread.
This looks like something particular to your code. The parent prop is showing up both locally and on deployed Studios on my end.
sorry
user M
, but it's not our code
it's not showing up locally or on deployed studios for our project
this studio has been deployed for weeks
and these fields have not changed
(projectId:
3yki7x9c
, dataset:
production
)
if you check the screenshot farther up the thread, you can see something is wrong... the
value
prop is returning the entire object instead of the specific field value this is defined in.
Definitely not something with our code, considering that and the fact that we have had this setup live and working for weeks.
Actually
user M
I have narrowed it down, it seems to only behave this way the moment you attach a
fieldset
to a conditional field...
this definitely used to not be the case, so it sounds like there's a degredation with fields that use a
fieldset
and
hidden
attribute.
Can you share the code for the field that’s behaving this way?
yup one sec!
full object schema as well ☝️
Hmm, it looks like it’s still working on my end. I’ll keep exploring, though.
Ok, I was able to replicate. I don’t know if they knowingly changed the behavior. Did you update the version of the Studio today or did it come up out of the blue entirely?
Until we track it down, can you move the conditional to the fieldset itself to get around it?

    {
      title: 'Custom Aspect Ratio',
      name: 'aspectRatio',
      options: {columns: 2},
      hidden: ({ parent }) => parent?.graphicAspectRatio !== 'custom', 
    },
I did not update the studio version today, so it does seem to have come up out of the blue!
Wait, it seems like it suddenly is working normally again for me. I don’t know what’s happening but I’ll get this logged so that the DX Studio team can start triaging.
sounds good, yea I was just going to say I tried to add this to the fieldset itself, but no dice
(and tbh I didn't even know that was possible 😅)
Hi
user J
long time - did it get sorted?
hey there
user A
! Not yet, it sounds like it was getting logged for the DX team to look at?
user A
I logged it in shortcut yesterday and alerted the Studio team.
Just out of curiousity - did this happen with an upgrade
user J
- or just out of the blue?
Hey there
user M
! Just curious if there was any movement on this one by chance?
Let me check!
Hey everyone! Got the same problem after updating to 3.11.5. Is there any success in resolving that?
I haven't heard any movement on this, would love to know when this will be prioritized, since it's a pretty glaring issue for a pretty generic setup 😕
Thanks for chasing
user J
and apologies for this taking time to make it to the top of the list. Fix is out in latest release.
This is great! Thank you!
All good, thank you fam! 🙌
Wow just ran into this myself. And there's a fix out. Hooray! 🙏

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.

Was this answer helpful?