-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gatsby-remark-images in MDX doesn't generate base64 placeholders #15058
Comments
I believe
For Gatsby v2, However, I'm currently experiencing this same issue with gatsby-mdx so I'm inclined to think this doesn't play a role in the issue. |
gatsby-plugin-mdx was the gatsby-1-compatible version and gatsby-mdx the 2.0 compatible version. Since I'm in the process of giving gatsby-mdx to the gatsby monorepo in #14657, we're also doing a rename with the gatsby-mdx 1.0 release. The future-facing package will be gatsby-plugin-mdx@1.0. I'll make this clear when I write and release the official gatsby-mdx 1.0 blog post. Until then the gatsby-plugin-mdx package is basically "dark launched". |
Thanks for clarifying @ChristopherBiscardi, and thanks for your work on the amazing plugin! 🎉 ...now about these missing base64 placeholders, any thoughts? 😛 |
@robinmetral I haven't had a chance to look into it yet since I just got back from vacation yesterday :) Thanks for this issue and the repro repo, that'll make it much easier to figure out what's going on. |
Thank you! Let me know if there's anything else I can do 🙂 |
Glad I found this already reported by @robinmetral as I was about to do it myself! 😛 |
This is likely related to #15486 The proposed solution there by @cwgw solves this problem. The problem: workaround: supply the name of the plugin under a new {
resolve: `gatsby-plugin-mdx`,
options: {
gatsbyRemarkPlugins: [
{
resolve: `gatsby-remark-images`,
options: {
maxWidth: 1152,
linkImagesToOriginal: false,
quality: 75,
withWebp,
},
},
],
plugins: ['gatsby-remark-images'],
},
}, |
I'm not sure that this is related to #15486. The problem there is that gatsby api files (like However, the base64 placeholder isn't generated in one of those gatsby api files. I think this issue may be something else. |
@cwgw fair enough, adding it to the plugins array did bring back the blur up effect but could be unrelated cause |
@ChristopherBiscardi I was just about to open an issue on this, but just found it has already been reported. Steps to reproduce:
My debugging into https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-remark-images/src/index.js#L339 but i'm not sure i understand what's actually happening in that plugin and especially don't understand the interaction between |
Hi @codepunkt. Images in markdown can come in both markdown syntax and regular html. gatsby-remark-images has to distinguish between the two because they require different handling.
The plugin traverses the tree looking for markdown image nodes and pushes each to the HTML is complicated because images can be nested within other elements. So, the plugin uses cheerio to parse each html node and find and replace |
The Not sure where the Will dig in deeper. |
It seems the Not sure what i can do about that. Would be great if someone could chime in that knows how these things work. |
Just a thought, but can you ensure that all |
All Plugin finds |
I've been debugging this via Visual Studio Code using my own site and I can see it does indeed retrieve the associated file, gets the base64 data and finally sets the AST node type to "html" and sets the value in it. But somehow, seems that the |
Nice digging @codepunkt and @pedrolamas! My hunch is that the style attribute is being entirely dropped by React because it's formatted as a string rather than an object which is what JSX requires (which is what MDX is compiling to). We have a babel plugin that handles some of coercion from HTML nodes to JSX, but it looks like this particular case is being missed. |
I think we are getting somewhere now: that babel plugin uses the to-style to convert the string representation of the I need to run further tests on it, but this might be the culprit as I don't see where it handles the |
Confirmed: the issue is with the to-style package! These are calls to that specific function, differing only that on the first you have "data:image" as part of the url, and the other "data_image" (so I removed the ":" from the url)
As you can see, it successfully added the background-image on the second example, so the problem is here! We fix the to-style package, we fix our problem! |
Amazing @pedrolamas, thanks for digging. Are you opening a PR? |
@robinmetral I have a fix now, some more tests and will push a fix in a couple of hours! |
@pedrolamas @robinmetral @johno Seems like this is a problem that needs fixing. Great job! However, the data-uri is never generated in my case with the plugin bailing out right before generating it because the file is not found in files array. Here: A reproducible example is here: |
Cleaned my example branch up to be able to spot the problem easier. The
The
The Because of this difference, the comparison between the actual file Could this be a generic problem with windows paths/drive letters in Gatsby? I could fix it in |
@codepunkt I do know that Gatsby on Windows is not as seamless as on Unix. If you think this might be a broader problem, it might deserve its own issue! |
I don't even know where to begin. Whenever windows drive letters are in paths, Gatsby has to either lowercase them or uppercase them, but be consistent about it. I know it has also been a problem in node and has occured in webpack, yarn and lots of other tools. As of now, i'd just like placeholder images 😭 |
So here's the situation: the dependency on There's an open issue on this matter, but seems to me that this codebase is abandoned (there are open PR's from 2017!) I'd recommend in using I've found 2 places where this package is in use:
While we can use Ideally, this should be fixed on the |
I've made a PR that replaces Smooth transitions might still be failing but I was going to leave that for when this gets approved/merged in the master branch. |
Looking great @pedrolamas, looking forward to seeing this merged and fixed! Thank you 🚀 |
My PR has shipped in the latest Gatsby and MDX dependencies, and from my tests, seems this issue is no more! 🙂 |
Description
Using
gatsby-remark-images
in MDX (see this guide) doesn't generate a base64 placeholder.➡️ demo repo ⬅️
➡️ live example ⬅️
Steps to reproduce
gatsby new gatsby-image-with-mdx
cd gatsby-image-with-mdx
yarn add gatsby-plugin-mdx @mdx-js/mdx @mdx-js/react gatsby-remark-images
gatsby-config.js
:/src/posts/testing-gatsby-image/index.mdx
:image.png
gatsby-node.js
:/src/templates/post.js
:gatsby develop
Expected result
The generated markup should include a base64 placeholder image for the "blur up" effect, like when using
gatsby-remark-images
withgatsby-transformer-remark
.Actual result
Generated markup:
Environment
The text was updated successfully, but these errors were encountered: