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

Pass projectId and dataset to the block renderer (only after using my own extended serializer)

Open logemann opened this issue 2 years ago • 1 comments

When trying to build my gatsby site, i am getting this error after using block-content-to-react in more places than before. I dont get it when building locally.

upgraded to latest version of block-content-to-react without solving it. I dont even get the error message.

3:02:19 AM: error Building static HTML failed for path "/malte-brix-es-muss-gerechtigkeit-her/"
3:02:19 AM: 
3:02:19 AM:   40 |
3:02:19 AM:   41 |   if (!projectId || !dataset) {
3:02:19 AM: > 42 |     throw new Error(materializeError);
3:02:19 AM:      | ^
3:02:19 AM:   43 |   }
3:02:19 AM:   44 |
3:02:19 AM:   45 |   var ref = asset._ref;
3:02:19 AM: 
3:02:19 AM:   WebpackError: You must either:
3:02:19 AM:   
3:02:19 AM:   - getImageUrl.js:42 
3:02:19 AM:     [BrixLangeKanzleipage]/[@sanity]/block-content-to-hyperscript/lib/getImageUr    l.js:42:1
3:02:19 AM:   
3:02:19 AM:   - serializers.js:127 
3:02:19 AM:     [BrixLangeKanzleipage]/[@sanity]/block-content-to-hyperscript/lib/serializer    s.js:127:1
3:02:19 AM:   
3:02:19 AM:   - construct.js:3 
3:02:19 AM:     [BrixLangeKanzleipage]/[@babel]/runtime/helpers/construct.js:3:32
3:02:19 AM:   
3:02:19 AM:   - construct.js:13 
3:02:19 AM:     [BrixLangeKanzleipage]/[@babel]/runtime/helpers/construct.js:13:1
3:02:19 AM:   
3:02:19 AM:   - static-entry.js:263 
3:02:19 AM:     BrixLangeKanzleipage/.cache/static-entry.js:263:20

logemann avatar Aug 31 '21 06:08 logemann

After digging into the source, i can at least read the complete error message as it should be on the netlify console:

var materializeError = "You must either:\n - Pass projectId and dataset to the block renderer\n - Materialize images to include the url field.\n\nFor more information, see ".concat(generateHelpUrl('block-content-image-materializing'));

Update:

When providing projectId and dataset on the PortableText component, image now works again: <PortableText projectId={"xxxxx"} dataset={"production"} blocks={blocks} serializers={serializers(allSanityVideos)}/>

but what i dont get. Before using my own serializer, i ve used this one without being forced to use projectId and dataset:

const BlockRenderer = props => {
  return BlockContent.defaultSerializers.types.block(props)
}
<PortableText blocks={post._rawBody} serializers={{
                                  block: BlockRenderer,
                                  types: {block: BlockRenderer}
                                }}/>

Can somebody point me to the right direction why in some circumstances one needs to supply those attributes and sometimes not? In the sourcecode i ve seen something like this:

// When rendering images, we need project id and dataset, unless images are materialized

So it seems before the images where materialized. Whatever this means ;-)

logemann avatar Aug 31 '21 07:08 logemann

Closing this, as the new @portabletext/react library is the successor to this module. Please see https://github.com/portabletext/react-portabletext

rexxars avatar Jan 31 '23 01:01 rexxars