-
-
Notifications
You must be signed in to change notification settings - Fork 75
[postcss-custom-properties] issue when used with postcss-html (document node) #595
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
Comments
@lubomirblazekcz Can you provide a full reproduction? The CSS on its own works fine : :root {
--blue: blue
}
body td {
color: var(--blue)
}
@media all and (max-width: 600px) {
body {
color: red;
}
} becomes : :root {
--blue: blue
}
body td {
color: blue
;
color: var(--blue)
}
@media all and (max-width: 600px) {
body {
color: red;
}
} |
It's mentioned in ota-meshi/postcss-html#68, with that html you get the non-working result. @ota-meshi mentioned that it's actually a problem with document nodes, which postcss-custom-properties might not support. I don't know if that is something that can be fixed though. |
I have no idea how to add support for document nodes (or what they are) :/ A quick check does reveal that It does this for the On |
Ok no worries, I've actually came with a workaround for my usecase. But I've created this issue in case if it is something that can be fixed perhaps :) |
@ai I missed We still have a few plugins with This example can't be processed with the new visitor API. .a {
color: var(--color);
}
:root {
--color: red;
} I can update our plugin to use Once: (root) => {
customProperties = getCustomPropertiesFromRoot(root, { preserve });
}, becomes : Once: (root) => {
customProperties = getCustomPropertiesFromRoot(root, { preserve });
},
Document: (document) => {
customProperties = new Map();
document.nodes.forEach((node) => {
if (node.type !== 'root') {
return;
}
for (const [key, value] of getCustomPropertiesFromRoot(node, { preserve }).entries()) {
customProperties.set(key, value);
}
});
}, Event callback order and counts become for the original example :
This might work in practice. Because I don't know the API I also don't know if this will cause issues with other syntaxes or plugins. The docs also say that this API is still experimental. Any insights you might have would be greatly appreciated 🙇 |
@lubomirblazekcz I just ran this through our test suite and it would require us to bump the minimum PostCSS version for our plugins.
We keep this version relatively low because some frameworks pin the PostCSS version, making it impossible for end users to correctly manage their own dependencies. Keeping it low means there is more margin for error in those frameworks. Update : this was added in |
Ok, I understand. Maybe it can be updated in the future then :) |
Initially |
thank you @ai I think it makes sense for It will take a while before we have the capacity for this as this will be a very large change. We would need to update our test suite and every plugin that uses |
There doesn't seem to be a lot of interest from the community in getting this fixed. |
Bug description
Custom properties are not transformed correctly with
postcss-html
, this might be problem with document node support as mentioned in ota-meshi/postcss-html#68Source CSS
Expected CSS
Actual CSS
Does it happen with
npx @csstools/csstools-cli <plugin-name> minimal-example.css
?No response
Debug output
No response
Extra config
No response
What plugin are you experiencing this issue on?
PostCSS Custom Properties
Plugin version
12.1.8
What OS are you experiencing this on?
macOS
Node Version
18.6.0
Validations
Would you like to open a PR for this bug?
The text was updated successfully, but these errors were encountered: