Issue with string previews not rendering when options are defined in Sanity.io

17 replies
Last updated: Aug 11, 2021
I’ve recently run into an issue where
string
previews don’t render when a list of options is defined. Once the options are removed, opening this
string
type to any value, the Preview works as expected. Previously this was not an issue, so I’m wondering if the latest Sanity update introduced this bug.
Thanks for any help! Schema code attached in thread.
Jul 22, 2021, 5:55 PM
//pieces.js
export default {
  name: "pieces",
  title: "Pieces",
  type: "object",
  fields: [
    // ...
    {
      title: "Width",
      name: "size",
      type: "string",
      description: "What size would you like this to appear at?",
      validation: (Rule) => Rule.required().error(`Gotta choose a width!`),
      options: {
        list: [
          { title: "Small", value: "small" },
          { title: "Medium", value: "medium" },
          { title: "Large", value: "large" },
          { title: "X-Large", value: "xlarge" },
          { title: "Full", value: "full" },
        ],
      },
    },
  ],
  preview: {
    select: {
      title: "data.content.title",
      media: "data.content.socialImage",
      subtitle: "size",
    },
    prepare(selection) {
      const { title, media, subtitle } = selection;

      return {
        title: title,
        media: media,
        subtitle: subtitle ? `Size: ${subtitle}` : null,
      };
    },
  },
};
Jul 22, 2021, 5:56 PM
Note: any unrelated code was removed for brevity. Thanks again for your help!
Jul 22, 2021, 5:58 PM
//pieces.js
export default {
  name: "pieces",
  title: "Pieces",
  type: "object",
  fields: [
    // ...
    {
      title: "Width",
      name: "size",
      type: "string",
      description: "What size would you like this to appear at?",
      validation: (Rule) => Rule.required().error(`Gotta choose a width!`),
      options: {
        list: [
          { title: "Small", value: "small" },
          { title: "Medium", value: "medium" },
          { title: "Large", value: "large" },
          { title: "X-Large", value: "xlarge" },
          { title: "Full", value: "full" },
        ],
      },
    },
  ],
  preview: {
    select: {
      title: "data.content.title",
      media: "data.content.socialImage",
      subtitle: "size",
    },
    prepare(selection) {
      const { title, media, subtitle } = selection;

      return {
        title: title,
        media: media,
        subtitle: subtitle ? `Size: ${subtitle}` : null,
      };
    },
  },
};
Jul 22, 2021, 5:56 PM
Note: any unrelated code was removed for brevity. Thanks again for your help!
Jul 22, 2021, 5:58 PM
Interesting. Your preview works for me both with and without
options.list
.
Jul 22, 2021, 6:10 PM
You mentioned that you recently ran into the issue. Was this same code working before but now isn’t? Or is this the first time you’ve tried it?
Jul 22, 2021, 6:11 PM
What are your
sanity versions
?
Jul 22, 2021, 6:11 PM
What are your
sanity versions
?
Jul 22, 2021, 6:11 PM
Weird! Everything seems up to date on my end.
@sanity/cli             2.13.0 (latest: 2.13.1)
@sanity/base            2.13.1 (up to date)
@sanity/cli             2.13.1 (up to date)
@sanity/color-input     2.13.0 (up to date)
@sanity/components      2.13.0 (up to date)
@sanity/core            2.13.1 (up to date)
@sanity/dashboard       2.13.1 (up to date)
@sanity/default-layout  2.13.1 (up to date)
@sanity/default-login   2.13.1 (up to date)
@sanity/desk-tool       2.13.1 (up to date)
@sanity/vision          2.13.1 (up to date)
Jul 22, 2021, 6:36 PM
Weird! Everything seems up to date on my end.
  "dependencies": {
    "@sanity/base": "^2.13.1",
    "@sanity/color-input": "^2.13.0",
    "@sanity/components": "^2.13.0",
    "@sanity/core": "^2.13.1",
    "@sanity/dashboard": "^2.13.1",
    "@sanity/default-layout": "^2.13.1",
    "@sanity/default-login": "^2.13.1",
    "@sanity/desk-tool": "^2.13.1",
    "@sanity/vision": "^2.13.1",
Jul 22, 2021, 6:36 PM
Currently running
@sanity/cli version 2.13.0
Jul 22, 2021, 6:36 PM
You caught a regression. It worked when I was on 2.13.0. Just upgraded to 2.13.1 and now get the same behaviour. I’m just working out which plugin causes it.
Jul 22, 2021, 6:49 PM
I appreciate your help with this, User!
Jul 22, 2021, 6:50 PM
My pleasure! It was @sanity/base. Rolling back to 2.13.0 worked for me. The way I did it was to delete node_modules, change the line in package.json to
"@sanity/base": "2.13.0",
, and then run
sanity install
. I’m just checking into what caused the regression.
Jul 22, 2021, 6:58 PM
Thanks again, User! I’ll roll back a version now and will keep a lookout for future updates. 👍
Jul 22, 2021, 6:59 PM
Thanks for reporting this, User. I’ve logged the issue here . I’ll mark this thread as completed as that issue will be the best place to track this, but I’ll try to follow up if I get word of a fix.
Jul 22, 2021, 7:28 PM
Hi User. 2.14.0 was released and resolves this issue. Please follow up if you notice any concerns. Thanks for reporting and for your patience! 🙌
Aug 11, 2021, 2:09 PM

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?