Troubleshooting a gallery block error in a page builder
The error you're seeing — Invalid item type: "[object Object]". Default array input can only contain objects (for now) — typically happens when you're trying to nest an array inside another array, which the default array input doesn't support directly.
For a page builder gallery block, you probably have something like this structure that's causing the issue:
// ❌ This won't work - array inside array
{
name: 'gallery',
type: 'array',
of: [
{
type: 'array', // <- Problem: nested array
of: [
{
type: 'object',
fields: [
{name: 'image', type: 'image'},
{name: 'caption', type: 'string'},
{name: 'alt', type: 'string'}
]
}
]
}
]
}The solution is to wrap your gallery in an object type first, then have the array of images inside that object:
// ✅ This works - object containing an array
{
name: 'pageBuilder',
type: 'array',
of: [
{
name: 'gallery',
type: 'object',
fields: [
{
name: 'images',
type: 'array',
of: [
{
type: 'object',
fields: [
{name: 'image', type: 'image'},
{name: 'caption', type: 'string'},
{name: 'alt', type: 'string'}
]
}
]
}
]
}
// ... other page builder blocks
]
}This structure gives you a page builder array that contains gallery block objects, and each gallery object has its own array of image objects with captions and alt text.
If you want to make the gallery block reusable across your schema, you can define it as a separate schema type:
// schemas/galleryBlock.js
export default {
name: 'galleryBlock',
type: 'object',
title: 'Gallery',
fields: [
{
name: 'images',
type: 'array',
of: [
{
type: 'object',
fields: [
{name: 'image', type: 'image'},
{name: 'caption', type: 'string'},
{name: 'alt', type: 'string'}
]
}
]
}
]
}Then reference it in your page builder:
{
name: 'pageBuilder',
type: 'array',
of: [
{type: 'galleryBlock'},
// other blocks...
]
}The key takeaway from the array fields documentation is that arrays can contain objects or references, but when you need nested arrays, you must wrap them in an object type first. This is the standard pattern for page builder implementations where you need complex, nested content structures.
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.