block-content-to-hyperscript icon indicating copy to clipboard operation
block-content-to-hyperscript copied to clipboard

Missing serializers for block type figure

Open bjornarhagen opened this issue 6 years ago • 7 comments

Version 2.0.7

I'm making a website using the NextJS landing page template made by you guys: https://github.com/sanity-io/sanity-template-nextjs-landing-pages.

If I insert an image in a text box (type: portableText), it creates the following error:

Error: Unknown block type "figure", please specify a serializer for it in the 'serializers.types' prop

If I add the following code to src/serializers.js under funciton BlockSerializer(props), it fixes the error:

if (blockType === 'figure') {
    serializer = serializers.types['image'];
}

Is there any good way to fix this locally without editing the file directly inside node_modules, or will you guys be able to provide a fix within some days?

bjornarhagen avatar Aug 06 '19 15:08 bjornarhagen

to fix this locally without editing the file directly inside node_modules

const serializers = { types: { figure: ({ node: { asset, caption } }) => { return <img src={asset} alt={caption} />; } } };

gsdavris avatar Nov 13 '20 10:11 gsdavris

Im having the same error: Error: Unknown block type "localeBlockContent", please specify a serializer for it in the serializers.types prop

ut where do I put the solution? Thank you!

JoseGarciaM avatar Nov 19 '20 19:11 JoseGarciaM

do you use @sanity/block-content-to-react ??

https://github.com/sanity-io/block-content-to-react

gsdavris avatar Nov 20 '20 07:11 gsdavris

Yes =). And if my type in my schema is just blockContent it works fine, but with the type localeBlockContent it crashes

JoseGarciaM avatar Nov 22 '20 15:11 JoseGarciaM

Same issue here. I add the serializer but I get the following error:

Uncaught Error: Unknown block type "photo", please specify a serializer for it in the `serializers.types` prop
//serializer
...
const serializers = {
  types: {
    photo: ({ node }) => {
      if (!node.asset) return null
      return <Image src={node.asset} alt=" " />
    },
  },
}

//block
<BlockContent
    blocks={page._rawHeroContent}
    serializers={serializers}
/>

mindmergedesign avatar Jan 17 '21 21:01 mindmergedesign

What is this error Error: Unknown block type "undefined", please specify a serializer for it in the serializers. types prop

This error happened while generating the page. Any console logs will be displayed in the terminal window.

<PortableText // Pass in block content straight from Sanity.io content={blogs[0].content} projectId= "o80s1fnk" dataset= "production" // Optionally override marks, decorators, blocks, etc. in a flat // structure without doing any gymnastics

  serializers={{
    h1: (props) => <h1 style={{ color: "red" }} {...props} />,
    li: ({ children }) => <li className="special-list-item">{children}</li>
   
  }}
/>

gulshkr avatar Jun 11 '22 07:06 gulshkr

same error error - Error: Unknown block type "undefined", please specify a serializer for it in the serializers.types prop

  <PortableText
      // Pass in block content straight from Sanity.io
      content={blogs[0].content}
      projectId="oeqragbg"
      dataset="production"
      // Optionally override marks, decorators, blocks, etc. in a flat
      // structure without doing any gymnastics
      serializers = {{
        h1: (props) => <h1 style={{ color: "red" }} {...props} />,
        li: ({ children }) => <li className="special-list-item">{children}</li>,
        
      }}
    />

TechDevSaga avatar Jun 22 '22 09:06 TechDevSaga