Next.js Conf 2024: Your app should be Live by Default – Watch Keynote

Regression in Sanity causing custom type preview issues

5 replies
Last updated: Aug 11, 2021
Hello! Just updated all sanity modules up to date using
sanity upgrade
and now a custom type I’ve made is not working out for me. The type looks like this:

export default {
    name: 'portals',
    type: 'array',
    of: [{type: 'string'}],
    initialValue: ['vt', 'vtna', 'vb', 'rt', 'udt'],
    options: {
      list: [
        {title: 'Trucks', value: 'vt'},
        {title: 'Trucks North America', value: 'vtna'},
        {title: 'Buses', value: 'vb'},
        {title: 'R Trucks', value: 'rt'},
        {title: 'U Trucks', value: 'udt'},
      ]
    },
    validation: (Rule) => Rule.required(),
}
And I use this in another type under its fields:


      {
        title: 'Portals',
        description: 'The portals in which this API should be available in',
        name: 'portals',
        type: 'portals',
      },
And I have a preview using the portals type:


preview: {
    select: {
      title: 'apiName',
      portals: 'portals',
      id: '_id',
    },
    prepare({title, portals, id}) {
      console.log(portals);
      const subtitle = portals.join(", ").toUpperCase()
      const isDraft = id.substring(0,5) == 'draft' ? '👷' : '✅'
      return {
        title: title,
        subtitle: subtitle,
        media: <span style={{fontSize: '1rem'}}>{isDraft}</span>
      }
    }
  }
The issue is that the portals variable is always undefined. Am I missing something? Thanks!
Aug 10, 2021, 9:13 AM
You’re not missing anything!
There was a regression with list options not being correctly rendered in previews, this has been fixed and should hopefully be out in the next studio release


https://github.com/sanity-io/sanity/issues/2631
Aug 10, 2021, 11:57 AM
Sweet! When will this release be out?
Aug 10, 2021, 12:00 PM
And is there a quick fix that one can use in the meantime?
Aug 10, 2021, 1:56 PM
Hi User! I’m not sure when it will be released, but the quick fix would be to either upgrade to the beta or downgrade
@sanity/base
to a version before 2.13.
Aug 10, 2021, 3:16 PM
This fix has just been released 😄
Aug 11, 2021, 10:15 AM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?