Skip to content
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

fix: prevent mangling of 'named timeline range names and percentages' in keyframe selectors #1518

Merged
merged 3 commits into from Sep 30, 2023

Conversation

johannesodland
Copy link
Contributor

@johannesodland johannesodland commented Aug 15, 2023

This PR fixes an issue reported in #1460

Keyframe selectors from scroll-driven animations (named timeline range name and percentage) are mangled by replacing 100% with to in keyframe selectors where it is not valid.

@keyframes test {
   entry 100% {
      color: red;
   }
}

/*
The keyframe-selector with a named timeline range name and percentage is mangled to:

@keyframes test {
   entry to {
      color: red;
   }
}
*/

This PR fixes the issue by only replacing 100% with to when the parent selector only has one child node.

@johannesodland johannesodland changed the title fix: prevent mangling of named timeline range names and percentages in keyframe selectors fix: prevent mangling of 'named timeline range names and percentages' in keyframe selectors Aug 15, 2023
@@ -163,7 +163,7 @@ const tagReplacements = new Map([
function tag(selector) {
const value = selector.value.toLowerCase();

if (tagReplacements.has(value)) {
if (tagReplacements.has(value) && selector.parent && selector.parent.nodes.length === 1) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for the long delay in answering. It looks fine, but could you maybe write a comment explaining what the selector.parent etc. check is trying to achieve?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I refactored and added comments to clarify the handling of simple vs complex tag selectors. 7c68ea8

I'm not sure if checking parent node length is the best way to differentiate between a complex or a simple selector. Do you know if there is a better way?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No better way comes to mind, in fact the codebase is full of this sort of parent checks. Partly I think it's because the parsers we use were mainly developed before the introduction of more recent CSS features.

@codecov
Copy link

codecov bot commented Sep 28, 2023

Codecov Report

All modified lines are covered by tests ✅

Files Coverage Δ
packages/postcss-minify-selectors/src/index.js 99.25% <100.00%> (+0.02%) ⬆️

📢 Thoughts on this report? Let us know!.

@ludofischer ludofischer merged commit 1947271 into cssnano:master Sep 30, 2023
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants