I encountered an issue in Sanity Studio.
When a field of Reference type is configured to be displayed conditionally, by adding a hidden property, it breaks after the condition changes. It becomes impossible to click on the reference in order to open a referenced document. It is fixed if I reload the page, but if the condition changed again, the issue appears again.
Below is a code example. Conditional logic was added as follows. The example repository is build upon a default Movie project Sanity template.
import {defineField, defineType} from 'sanity'
export default defineType({
name: 'castMember',
title: 'Cast Member',
type: 'object',
fields: [
defineField({
name: 'characterName',
title: 'Character Name',
type: 'string',
}),
// This field is used as a condition
defineField({
name: 'showActor',
title: 'Show Actor',
type: 'boolean',
}),
defineField({
name: 'person',
title: 'Actor',
type: 'reference',
to: [{type: 'person'}],
hidden: ({parent}) => !parent?.showActor, // Display `person` field if only `showActor` is `true`
}),
defineField({
name: 'externalId',
title: 'External ID',
type: 'number',
}),
defineField({
name: 'externalCreditId',
title: 'External Credit ID',
type: 'string',
}),
],
preview: {
select: {
subtitle: 'characterName',
title: 'person.name',
media: 'person.image',
},
},
})
This ticket got closed by a mistake, apologies @hrabiel. It is a duplicate of a known issue in our ticket tracking. We'll keep this ticket open and update status as we work on it
Describe the bug
I encountered an issue in Sanity Studio. When a field of Reference type is configured to be displayed conditionally, by adding a
hidden
property, it breaks after the condition changes. It becomes impossible to click on the reference in order to open a referenced document. It is fixed if I reload the page, but if the condition changed again, the issue appears again.Below is a code example. Conditional logic was added as follows. The example repository is build upon a default Movie project Sanity template.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
The referenced document should be opened successfully.
Screenshots
https://github.com/user-attachments/assets/9463c865-3db7-4663-a516-f87392fd244d
Which versions of Sanity are you using?
3.52.2
What operating system are you using?
MacOS Sonoma 14.5 (23F79)
Which versions of Node.js / npm are you running?
npm: 10.2.4 node: v20.11.1