rich text contentful target.fields undefined when using embedded-asset-block -Gatsby
See original GitHub issueIssue
Cannot read property ‘title’ of undefined. When trying to render the images inside a contentful rich text.
When I check the raw data in graphql fields
key is missing inside ‘embedded-asset-block’.target
##graphql
code
const options = {
renderNode: {
"embedded-asset-block": (node) => {
const alt = node.data.target.fields.title["en-US"];
const url = node.data.target.fields.file["en-US"].url;
return <img alt={alt} src={url} />;
},
},
};
return (
<Layout>
<Head title={props.data.contentfulBlogPost.title} />
<h1>{props.data.contentfulBlogPost.title}</h1>
<p>{props.data.contentfulBlogPost.publishedDate}</p>
{documentToReactComponents(
JSON.parse(props.data.contentfulBlogPost.body.raw),
options
)}
</Layout>
);
please help me to resolve this issue. I recently upgraded all the gatsby and gatsby plugins. So how can I embedd the images and videos in the rich text.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5
Top Results From Across the Web
Embedded images are ignored · Issue #61 · contentful/rich-text
It seems there are different fields if you're not using Gatsby's package. So rather than data.target.fields, you need to look for the links ......
Read more >Gatsby With Contentful Rich Text Images Not Displaying
Contentful Rich Text JSON, as you can see it detects that there are two images but it cannot see the file sources; the...
Read more >Rendering linked assets and entries in the Rich Text field
The power of the Contentful Rich Text field is that it offers a WYSIWYG ... and nodeType: "embedded-asset-block" — with empty content nodes....
Read more >No fields in node.data.target when trying to render embedded ...
The README.md shows the way to render rich text as the following: const options = { renderNode: { [BLOCKS.
Read more >gatsby-source-contentful
Displaying responsive image with gatsby-plugin-image ... Contentful Rich Text ... When using reference fields, be aware that this source plugin will ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have the same issue after updating gatsby-source-contentful to the latest version. It looks like the embedded resources don’t have the fileds prop anymore. I found that the fields are now flattered into the target object itself.
I don’t know the reason of this breaking change, maybe I am doing something wrong, but I have the feeling that the documentation about the new version of gatsby-source-contentful is very unclear.
Have you gone through the change log when upgrading to the new major version? This entry could be of interest to you.
For documentation on
renderRichText()
please see documentation on rich-text-react-renderer which is also applicable togatsby-source-contentful/rich-text
as stated in this Contentful / Gatsby guide or in the above change-log entry code example.