Array of PortableText blocks in Sanity schema causing length error
The issue you're encountering is that Sanity doesn't support nested arrays (arrays within arrays). When you define portableText as an array type and then try to include it in another array, you're creating a nested array structure, which causes the error.
The solution is to wrap your portable text array inside an object type, then create an array of those objects. Here's how to fix it:
Solution: Use an Object Wrapper
// PortableText component - change to an OBJECT, not array
export default defineType({
name: 'portableTextBlock',
title: 'Portable Text Block',
type: 'object', // Changed from 'array' to 'object'
fields: [
{
name: 'content',
title: 'Content',
type: 'array',
of: [{
type: 'block',
styles: [...],
marks: {...}
}]
}
]
})
// Inside your other document
{
name: 'grow_notes',
title: 'Grow notes',
type: 'array',
of: [{type: 'portableTextBlock'}],
group: 'content',
}Now your admins can add multiple portable text sections, and each one will be independently editable.
Alternative: Define Inline
If you prefer not to create a separate schema file, you can define the object inline:
{
name: 'grow_notes',
title: 'Grow notes',
type: 'array',
of: [
{
type: 'object',
name: 'textSection',
fields: [
{
name: 'content',
title: 'Content',
type: 'array',
of: [{type: 'block'}]
}
]
}
],
group: 'content',
}The fundamental rule to remember: array → object → array is valid, but array → array is not supported in Sanity's data structure. This limitation exists because of how the data store handles real-time collaboration and unique _key identifiers for array items.
Show original thread2 replies
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.