Join our next Developer Virtual Meetup – Live Q&A, Project Showcase, Swag raffle, and more 🔥

Discussion about errors with block content to React and adding a serializer for a citation type in a new project.

43 replies
Last updated: Oct 4, 2021
Hello! New to the Slack, been using and really enjoying Sanity for a bit now. I'm having some trouble with block content to React on a new project -- is anyone around who could chat about some errors I'm getting?
Oct 1, 2021, 2:59 PM
What errors are you getting?
Oct 1, 2021, 3:24 PM
Hi
user Y
! I'm using
@sanity/block-content-to-react
and adding a serializer for the
citation
type that I've added in, but I keep getting
Unknown block type "undefined", please specify a serializer for it in the `serializers.types` prop
Oct 1, 2021, 3:26 PM
I tried two different ways of implementing the custom block within my schema and got the same error both times. Happy to share how I structured that if it's helpful.
Oct 1, 2021, 3:27 PM
This suggests that there’s something up with the
blocks
data I think
Oct 1, 2021, 3:27 PM
Is it the whole Portable Text array? Do you see anything funky with the data if you console.log it?
Oct 1, 2021, 3:28 PM
Is it the whole Portable Text array? Do you see anything funky with the data if you console.log it?
Oct 1, 2021, 3:28 PM
That's part of what's interesting, the date looks pretty normal in the console log, but I don't see any
type
attached to any of the children. Could that be part of the problem?
Oct 1, 2021, 3:29 PM
The
_type: 'citation'
 should be on the root objects. So there might be something going on here. Are you using framework or anything?
Oct 1, 2021, 3:31 PM
If you have code to look at, that’s helpful!
Oct 1, 2021, 3:31 PM
I do! One sec, I'll push up the latest code.
Oct 1, 2021, 3:33 PM
I do! One sec, I'll push up the latest code.
Oct 1, 2021, 3:33 PM
cool - where in the project do I find the serializer?
Oct 1, 2021, 3:38 PM
cool - where in the project do I find the serializer?
Oct 1, 2021, 3:38 PM
hmm… weird. looks alright to me
Oct 1, 2021, 3:41 PM
is the dataset private?
Oct 1, 2021, 3:43 PM
Currently yes unfortunately. Would looking at the schema help? I built it here: https://github.com/throneless-tech/recoding-tech/blob/design-implementation/studio/schemas/portable_text.js
Oct 1, 2021, 3:43 PM
ah, this is an annotation
Oct 1, 2021, 3:46 PM
ah, this is an annotation
Oct 1, 2021, 3:46 PM
try to put it under
marks
 instead of
types
 in the serializer
Oct 1, 2021, 3:47 PM
Yes! Is the structure incorrect?
Oct 1, 2021, 3:47 PM
ah, this is an annotation
Oct 1, 2021, 3:46 PM
Ah gotcha, thanks so much. I'll give that a try
Oct 1, 2021, 3:47 PM
I suspect it’s this pattern that you’re trying at https://www.sanity.io/guides/portable-text-internal-and-external-links
Oct 1, 2021, 3:47 PM
Ah yes that's exactly what I was working from
Oct 1, 2021, 3:49 PM
So progress, I'm getting a new error 😆
TypeError: Cannot read property 'find' of undefined
Oct 1, 2021, 3:51 PM
It feels like you're not getting data into the component
Oct 1, 2021, 3:53 PM
It's definitely reading other fields that I've added, like the title and even other references. And if I log the object, all the data appears to be there
Oct 1, 2021, 3:55 PM
It's definitely reading other fields that I've added, like the title and even other references. And if I log the object, all the data appears to be there
Oct 1, 2021, 3:55 PM
Now getting the error
TypeError: can't access property "find", markDefs is undefined
Oct 1, 2021, 4:02 PM
Now getting the error
TypeError: can't access property "find", markDefs is undefined
Oct 1, 2021, 4:02 PM
I need to run offline for a bit but will be back and would love to hear if you have any other ideas. Thanks so much for your help this far!
Oct 1, 2021, 4:08 PM
I need to run offline for a bit but will be back and would love to hear if you have any other ideas. Thanks so much for your help this far!
Oct 1, 2021, 4:08 PM
Now getting the error
TypeError: can't access property "find", markDefs is undefined
Oct 1, 2021, 4:02 PM
It would help to access the data. I’m not super familiar with Stackbit, and it’s not super clear to me how they handle the data fetching
Oct 1, 2021, 4:10 PM
Haha ok totally fair, I'm not sure either. Makes sense that it could be something with stackbit, and I'll see if I can make the dataset accessible!
Oct 1, 2021, 6:18 PM
Haha ok totally fair, I'm not sure either. Makes sense that it could be something with stackbit, and I'll see if I can make the dataset accessible!
Oct 1, 2021, 6:18 PM
Hi
user Y
! Following up on this because I think I figured out the problem and am submitting a PR to stackbit. My new question though is how best to format a serializer for an annotation. Is there a recommended format for adding a mark that's a reference? I see the example usage for a mark that's a highlighter, but what if the mark is a reference to another record?
Oct 4, 2021, 6:45 PM
Hi
user Y
! Following up on this because I think I figured out the problem and am submitting a PR to stackbit. My new question though is how best to format a serializer for an annotation. Is there a recommended format for adding a mark that's a reference? I see the example usage for a mark that's a highlighter, but what if the mark is a reference to another record?
Oct 4, 2021, 6:45 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?