I am not sure if something I have done wrong but after an update last week, something broke with my images that are coming from page content and are inside a <figure>
The culprit here is the span and more specific, the class css-nd8buu-Container. That basically makes the image to not be visible. See image below. There should be an icon right above the title.
If I use a it like this <div dangerouslySetInnerHTML={{ __html: page.content.rendered }} /> I don’t have the issue.
Is there something I can do to solve this? I am not sure what the core of the issue is.
Hey @ni.bonev I’m sorry to hear that you are still stuck with this.
As your repository is private, Could you please replicate the issue you are facing in a codesandbox or isolate it in a different public repo? This way the community will be able to take a look at it and help you
thanks for your reply. At this point I have spent some extra time and figured out what exactly is the issue so I can outline it below.
Issue is cause when loading html content from a wordpress page. The content is generated using Gutenberg and it is a figure with an image inside it. This is how the html looks in the client, after being processed by Html2React
The culprit of the issue is the span that gets generated on by image.tsx located in Html2React/processors/image.tsx.
As we can see there on line 20, the container(span) gets added if there is specific width/height specified. However when rendered on the front-end the image doesn’t get displayed. I have seen this technique before of using the padding-bottom and positioning the image absolute, but for some reason I cant figure out it breaks, in this case.
My current solution is to just override some css locally, which is of course not ideal at all.
I ran into this same issue trying to integrate my own theme’s block styles. It looks like gutenberg has changed the markup structure for image blocks at some point, and whatever Frontity is doing doesn’t seem to work anymore. I looked at the demo for Frontity Twenty Twenty to try and figure out what I was doing wrong, but it is still using the old markup format.
As an aside, what is the purpose of the height and width attributes on the span?
The frontity.org site is created with Frontity and the content is created with Gutenberg. Here you have the repository in case you want to have a look at it and get some ideas
I think it was @david the one who add it and I think it had something to do with the padding-bottom hack used to “reserve” the height of the image and avoid a content layout shift when it loads.
Also, it seems like the Gutenberg team has not solved this yet on their side, but I haven’t reviewed it lately to be honest: https://github.com/WordPress/gutenberg/issues/20650. It looks like there’s been some progress though.
I don’t have anything public that I could share. However, I can reproduce locally with the Frontity Twenty Twenty theme right out of the box. Adding images in the block editor results in the images being hidden on the front end due to the styles added by either Frontity or html2react. I was only able to fix by overriding things as suggested by ni.bonev above.
Note that this doesn’t happen on the demo for the Frontity Twenty Twenty theme, because the content there was generated before the change that broke things. You need to create new content in the block editor with a recent WP version to reproduce the issue.
Also, alignwide and alignfull styles can affect the result here. The issue appears with default width and floated images, but not with images that have the “alignwide” and “alignfull” classes.
I don’t know, honestly. That logic was added in a very old PR by @orballo some time ago, for the 1.0 version of Frontity. I would have to look into it.
But, yeah, we should try not to add or remove nodes from Gutenberg blocks.
If I remember correctly, that logic is needed for the padding hack to work, as in some contents, the image might not arrive inside a <figure>, and <img> needs to have position relative to parent.
Maybe the processor can be improved covering the case where the content has a <figure><img /></figure>, adding the <span> only when <img> is alone, and using <figure> as an absolute parent in the first case.