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
CSS Rules for @media and :hover are stripped out in v4 #728
Comments
You’re not outputting |
We aren't utilizing tailwind in our project. Is this now a requirement for using Maizzle v4? I tried using the official starter <!-- transactional.html -->
...
<block name="template">
<style>
.content {
width: 640px;
}
@media (max-width: 600px) {
.content {
width: 100%;
min-width: 100%;
}
}
.action {
color: red;
}
.action:hover {
color: blue;
}
</style>
<table class="content w-full font-sans">
...
<a class="action" href="https://maizzle.com">
... |
Right, my bad, misunderstood. Is there a specific reason you're outputting that I'll need to run some tests, but in the meanwhile does it work if you add |
I did try out the Also as mentioned above, we are using a custom transformer/filter Regarding the placement of the <!-- Layout -->
<!DOCTYPE {{{ page.doctype || 'html' }}}>
<html lang="{{ page.language || 'en' }}" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
...
<if condition="page.title">
<title>{{{ page.title }}}</title>
</if>
<style sass>
@import 'src/styles/main';
</style>
<block name="head"></block>
</head>
<body class="{{ page.class }}">
<div role="article" aria-roledescription="email" aria-label="{{{ page.title || '' }}}" lang="{{ page.language || 'en' }}">
<block name="template"></block>
</div>
</body>
</html> <!-- Template -->
<extends src="src/layouts/main.html">
<block name="head">
<style sass>
...
</style>
</block>
<block name="template">
...
</block>
</extends> Basically each template has few of their own styles that need to be transported to the Head and combined with the ones in the layout. Works really well in V3. |
Maizzle doesn't have a Sass CSS compiler, is that something custom that you're implementing? |
Yeah we just added a // config.js / config.production.js
const sass = require('sass');
module.exports = {
...
transform: {
sass: (content) => sass.compileString(content, { loadPaths: ['./'] }).css,
},
}; The issue exists with or without
So yeah, you'd have to split up the stylesheet quite carefully to avoid retaining unneeded classes by accident. Assuming I'm using <!-- Layout -->
<!DOCTYPE {{{ page.doctype || 'html' }}}>
<html lang="{{ page.language || 'en' }}" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
...
<if condition="page.title">
<title>{{{ page.title }}}</title>
</if>
<style sass>
@import 'src/styles/main';
</style>
<block name="head"></block>
</head>
<body class="{{ page.class }}">
<div role="article" aria-roledescription="email" aria-label="{{{ page.title || '' }}}" lang="{{ page.language || 'en' }}">
<block name="template"></block>
</div>
</body>
</html> <!-- Template -->
---
title: "Hello World"
---
<extends src="src/layouts/main.html">
<block name="head">
<style sass>
.content {
width: 640px;
@media (max-width: 600px) {
width: 100%;
min-width: 100%;
}
}
.heading {
text-transform: uppercase;
}
.action {
color: red;
&:hover {
color: blue;
}
}
</style>
</block>
<block name="template">
<div class="content">
<h1 class="heading">{{page.title}}</h1>
<button class="action">Action</button>
</div>
</block>
</extends> In <!-- v4 output (without data-embed) -->
<!DOCTYPE html>
<html lang="en" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<meta charset="utf-8">
</head>
<body>
<div role="article" aria-roledescription="email" aria-label="Hello World" lang="en">
<div style="width: 640px">
<h1 style="text-transform: uppercase">Hello World</h1>
<button style="color: red">Action</button>
</div>
</div>
</body>
</html> If we use <!-- v4 output (with data-embed) -->
<!DOCTYPE html>
<html lang="en" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<meta charset="utf-8">
<style>
.content {
width: 640px;
}
@media (max-width: 600px) {
.content {
width: 100%;
min-width: 100%;
}
}
.heading {
text-transform: uppercase;
}
.action {
color: red;
}
.action:hover {
color: blue;
}
</style>
</head>
<body>
<div role="article" aria-roledescription="email" aria-label="Hello World" lang="en">
<div class="content">
<h1 class="heading">Hello World</h1>
<button class="action">Action</button>
</div>
</div>
</body>
</html> We would have to carefully restructure the <!-- Example of separated input styles to make it work -->
...
<block name="head">
<style sass>
.heading {
text-transform: uppercase;
}
</style>
<style sass data-embed>
.content {
width: 640px;
@media (max-width: 600px) {
width: 100%;
min-width: 100%;
}
}
.action {
color: red;
&:hover {
color: blue;
}
}
</style>
</block>
... Then in <!-- v4 output (with multiple style tags with and without data-embed) -->
<!DOCTYPE html>
<html lang="en" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<meta charset="utf-8">
<style>
.content {
width: 640px;
}
@media (max-width: 600px) {
.content {
width: 100%;
min-width: 100%;
}
}
.action {
color: red;
}
.action:hover {
color: blue;
}
</style>
</head>
<body>
<div role="article" aria-roledescription="email" aria-label="Hello World" lang="en">
<div class="content">
<h1 style="text-transform: uppercase">Hello World</h1>
<button class="action">Action</button>
</div>
</div>
</body>
</html> By contrast in <!-- v3 output (without data-embed) -->
<!DOCTYPE html>
<html lang="en" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<meta charset="utf-8">
<style>
@media (max-width: 600px) {
.content {
width: 100%;
min-width: 100%;
}
}
.action:hover {
color: blue;
}
</style>
</head>
<body>
<div role="article" aria-roledescription="email" aria-label="Hello World" lang="en">
<div class="content" style="width: 640px;">
<h1 style="text-transform: uppercase;">Hello World</h1>
<button class="action" style="color: red;">Action</button>
</div>
</div>
</body>
</html> |
Hey sorry this took some time, the issue is with If you don't need that, the solution for now is to disable it: // config.production.js
module.exports = {
// ...,
inlineCSS: {
removeStyleTags: true,
},
removeUnusedCSS: true,
removeInlinedClasses: false,
} What happens is that |
Hello, Same problem here. I tried with the data-embed, but even with that I can't make it to keep the class for the hover. <!DOCTYPE {{{ page.doctype || 'html' }}}>
<html lang="fr" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
(...)
<style tailwindcss data-embed>
.footerButton {
transition: 0.3s;
}
.footerButton:hover {
background-color:#d9d9d9 !important;
transition: 0.3s;
}
</style>
(...)
</head>
<body>
(...)
</body> and in the template file (...)
<table class="w-full">
<tr>
<td class="rounded-3 p-10 sm:px-0 bg-[#f3f2f5] footerButton sm:w-full" align="center">
<table>
<tr>
<td>
<p class="text-center text-black text-14 leading-[100%]">
<a href="" class="no-underline text-black">
Hello world
</a>
</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
(...) I tried
Otherwise, I would be glad if you have a workaround to keep specific class names and not all of them. |
I found a workaround for my problem. I post it here in case it helps someone: I add an attribute called (...)
<table class="w-full">
<tr>
<td classtokeep="footerButton" class="rounded-3 p-10 sm:px-0 bg-[#f3f2f5] footerButton sm:w-full" align="center">
<table>
<tr>
<td>
<p class="text-center text-black text-14 leading-[100%]">
<a href="" class="no-underline text-black">
Hello world
</a>
</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
(...) And then I add in the config.production.js file
|
OK, this should be fixed in 4.1.1, give it a try 👍 |
While upgrading from
@maizzle/framework@3.7.3
and@maizzle/cli@1.4.0
I noticed the build output was different in v4. It seems like any@media {}
or:hover
rules were being stripped out.Example
I've tested in a minimal new project to confirm. This is the project:
package.json
config.production.js
src/layouts/main.html
src/templates/helloworld.html
Results
build_production/helloworld.html (v4 -- missing styles)
build_production/helloworld.html (v3)
It's possible I'm missing some new option/configuration, but after trying a bunch I am still unsuccessful in producing a valid (v3 like) output.
The text was updated successfully, but these errors were encountered: