Closed BigglesZX closed 3 years ago
Any success if you get rid of the name and title with type: 'block'
?
export default {
title: 'Content Blocks',
name: 'contentBlocks',
type: 'array',
of: [
{ type: 'block' },
...
@geoffreyjball Thanks for the reply – to be honest I think this was likely down to stale data in the dataset as I was making a bunch of schema changes early in the project. I've done several more Sanity + Next.js projects since and the issue has not appeared again. I'll close this and chalk it up to gremlins.
Versions
Issue
I'm just getting started with Sanity (+ NextJS) so I'm hoping I haven't made a rookie error here. I've started a project from scratch and this part of it deals with content modelling for a simple blog. I'm struggling with an error when trying to output the contents of a custom block field from a blog post.
Here is my (simplified) post document definition:
Here is the definition for my custom contentBlocks field type (slightly simplified):
And my simple Post component looks like this (
post
is injected bygetStaticProps
):However, upon requesting a post document path, I get the following error:
So it seems the BlockContent component is receiving a block of type
text
(even though, as you can see, none are defined in the field spec) and doesn't know what to do with it. If I inspect the contents ofpost.contentBlocks
, you can see the errant type in there (this is for an example post containing a line of text, an image block, followed by another line of text):I can solve this error by manually mapping the
text
type to the standard serializer forblock
:Despite the fix however I still don't understand why this is happening, but I've not found anyone else with the same issue so I'm pretty sure I'm doing something stupid.
I should also note that I've tested existing documents and new documents in case some previous definition was persisting, but the result is the same.
Any suggestions would be much appreciated! Please let me know if I can provide any more information. Thanks!