Closed sebastianblesgen closed 7 months ago
Ugh, tough one to track down! Looks like it's coming from a dependency in our removeInlinedSelectors
code, which tries to remove possibly-inlined CSS selectors.
The issue occurs in posthtml-attrs-parser
, which we use to parse HTML element attributes in order to handle said removal. This library currently trips on the ;
in the base64 string and produces a broken property value.
I tested with this custom Tailwind CSS utility, just in case expressions in Maizzle had anything to do (they don't):
@layer utilities {
.bg-base64-px {
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkAAIAAAoAAv/lxKUAAAAASUVORK5CYII=');
}
}
Then used it in the template:
<x-main>
<div class="bg-base64-px">
test
</div>
</x-main>
This is what posthtml-attrs-parser
produces for that node:
{
class: [ 'bg-base64-px' ],
style: { 'background-image': "url('data:image/png" },
compose: [Function (anonymous)]
}
For now one way to deal with it is to disable it:
// config.production.js
module.exports = {
// ...
removeUnusedCSS: {
removeInlinedSelectors: false,
},
}
Though keep in mind that will increase your HTML size, since unused CSS won't be purged anymore.
/cc @maltsev I'll try to add a failing test for this but think I'll need your help to fix it; we'll also need to backport it to v0.1.x
Opened a PR, once we get it fixed I'll work on backporting it to v0.1.2
so we can use it in Maizzle 4.x π
By the way, if you're using base64 in HTML emails:
Opened a PR, once we get it fixed I'll work on backporting it to v0.1.2 so we can use it in Maizzle 4.x π
Thanks! I'll release both versions (1.x and 0.1.x) after the 2nd PR will get merged.
@sebastianblesgen sorry this took a while, published v4.8.3
now that should fix it π
When I use a base64 image in the url plus the bg-no-repeat class, the url is not rendered well. I think there is a conflict trying to merge everything in the style attribute.
style="background-repeat: no-repeat; background-image: url('data:image/jpeg }}">
The url is trunc afeter jpeg and }} remains.Note: If I do not use the main layout then the class are not inlined as style (that is expected) and the url is correctly rendered .
My template (x-main is the one that is installed when I create the project):
Result: