Error with schema when used inside blockContent in Sanity Studio

15 replies
Last updated: Sep 26, 2021
Hello, this schema when used inside blockContent, gives me error

export default {
  name: "slideshow",
  title: "Slideshow",
  type: "array",
  of: [
    {
      type: "image",
      fields: [
        {
          name: "caption",
          type: "string",
          title: "Caption",
          options: {
            isHighlighted: true, // <-- make this field easily accessible
          },
        },
      ],
    },
  ],
};
The error i get is,


ypeError: (value || []).some is not a function
    at ArrayInput.render (/static/js/app.bundle.js:237432:44)
    at finishClassComponent (/static/js/vendor.bundle.js:20302:31)
    at updateClassComponent (/static/js/vendor.bundle.js:20252:24)
    at beginWork (/static/js/vendor.bundle.js:21762:16)
    at HTMLUnknownElement.callCallback (/static/js/vendor.bundle.js:3330:14)
    at Object.invokeGuardedCallbackDev (/static/js/vendor.bundle.js:3379:16)
    at invokeGuardedCallback (/static/js/vendor.bundle.js:3434:31)
    at beginWork$1 (/static/js/vendor.bundle.js:26345:7)
    at performUnitOfWork (/static/js/vendor.bundle.js:25296:12)
    at workLoopSync (/static/js/vendor.bundle.js:25272:22)

AI Update

Based on the error you're experiencing, the issue is that you're trying to use a standalone array schema as a custom block type within blockContent (Portable Text), but the schema structure isn't quite right for that purpose.

The error (value || []).some is not a function typically occurs when Sanity expects an object type but receives an array type definition directly. When you embed custom blocks in Portable Text, you need to define them as object types, not array types at the top level.

Here's how to fix your slideshow schema for use in blockContent:

export default {
  name: "slideshow",
  title: "Slideshow",
  type: "object", // Changed from "array" to "object"
  fields: [
    {
      name: "slides", // Wrap the array inside a field
      title: "Slides",
      type: "array",
      of: [
        {
          type: "image",
          fields: [
            {
              name: "caption",
              type: "string",
              title: "Caption",
              options: {
                isHighlighted: true,
              },
            },
          ],
        },
      ],
    },
  ],
  preview: {
    select: {
      slides: "slides",
    },
    prepare({ slides }) {
      return {
        title: "Slideshow",
        subtitle: `${slides?.length || 0} images`,
      };
    },
  },
};

Then in your blockContent definition, you can use it like this:

{
  name: 'body',
  type: 'array',
  of: [
    {type: 'block'}, // Standard rich text
    {type: 'slideshow'}, // Your custom slideshow block
  ]
}

The key difference is that custom blocks in Portable Text must be objects that contain your array, not arrays themselves. According to the array fields documentation, arrays need proper structure and the "of" property must define valid member types.

If you want the slideshow to appear inline with your text content, this object-based approach is the correct pattern. The array of images is now a field within the slideshow object, which can be properly embedded in your Portable Text content. This follows the same pattern described in the Block Content documentation for adding custom blocks like images and videos.

Is this an error within the studio?
Yes it is within the studio
nothing seems wrong in the schema. Do you have any plugins that work with this field? or any document level validations?
No document level validations, also no plugins here
I assume it doesn’t give you any errors if used outside of blockContent?
yes it doesnt' give any errors when used inside other schemas
Not sure, hopefully someone else can guess the reason. Just in case what studio version are you using?
latest one
Assuming
blockContent
is an array, then you’ll need to nest
slideshow
in an object to avoid the first limitation here .
Thank you
user A
and
user U
Assuming
blockContent
is an array, then you’ll need to nest
slideshow
in an object to avoid the first limitation here .
Hello
user A
, I'm a bit confused. How can I nest an array of images though?
user G
instead of making it the
array
type make an object type and put this slideshow as an array type into a field on this object type
user G
instead of making it the
array
type make an object type and put this slideshow as an array type into a field on this object type
Thanks

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?