Closed MorrisonCole closed 2 years ago
Hi!
This is expected behavior and not considered a bug. You can use https://developer.mozilla.org/en-US/docs/Web/CSS/:has if you need to style the wrapper.
I think this is a bug now since gatsby itself is throwing an error because of this:
This was fixed in https://github.com/gatsbyjs/gatsby/pull/37423
Preliminary Checks
Description
I think this is a bug since it was not behaviour in pre-V2 versions.
I've been upgrading a long-term project to MDX V2 and found that whilst everything else works, gatsby images have lost important styling.
Pre V2 the generated HTML for this example image was:
Post V2 it is now wrapped in an extra div:
The remark to mdx HTML plugin seems to now add a wrapping
<div>
to raw/HTML nodes which breaks styling in my case (I have full-bleed images that are part of a CSS grid, and nesting them under a div constrains them).Please note that does not appear to be solvable with the 'unwrap-images-plugin' or similar that are often mentioned since Gatsby adds this plugin after user plugins: https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-plugin-mdx/src/plugin-options.ts#L118
I suppose it could be worked around by transforming the HTML with a rehype plugin, but it would nice if those extra divs weren't there in the first place.
Reproduction Link
https://github.com/MorrisonCole/image-wrapping-repro
Steps to Reproduce
npm start
http://localhost:8000/
<div>
wrapper!Expected Result
Cat image doesn't have an extra
<div>
wrapper.Actual Result
Cat image has a wrapper.
Environment
Config Flags
No response