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 duplicate -webkit-backdrop-filter output #850

Conversation

RobinMalfait
Copy link
Contributor

This PR fixes an issue where using CSS that looks like this:

.foo {
  transition-property: -webkit-backdrop-filter, backdrop-filter;
}

Results in CSS that looks like this:

.foo {
  transition-property: -webkit-backdrop-filter, -webkit-backdrop-filter, backdrop-filter;
}

This PR solves it for the transition-property (internally TransitionProperty, so I think it's also solved for transition that uses that) only.

We currently do this by checking whether a PropertyId exists with VendorPrefix::None. If it does, then we will make sure to remove all other PropertyId's (with the same name). The idea is that the PropertyId with VendorPrefix::None will print the property with the correct values, including the vendor prefix.

If however you only use CSS that looks like this:

.foo {
  transition-property: -webkit-backdrop-filter;
}

Which is without the unprefixed version, then this is maintained in the output because no VendorPrefix::None exists in this case.

I feel like there might be a better spot to handle this (maybe even in parsing, or during printing) but wasn't to sure. I also explicitly scoped it to the transition-property for now but maybe this can be more generalized?

I also started from the failing tests (and slightly adjusted with more test cases) from this PR: #551, I also made sure that the original author is marked as a co-author.

Fixes: #403
Closes: #551

RobinMalfait and others added 2 commits November 5, 2024 13:05
Co-authored-by: LeoniePhiline <22329650+LeoniePhiline@users.noreply.github.com>
If you have the following CSS:
```css
.foo {
  transition-property: backdrop-filter;
}
```

Then the `backdrop-filter` will be prefixed such that it looks like
this:
```css
.foo {
  transition-property: -webkit-backdrop-filter, backdrop-filter;
}
```

However, if you already have `-webkit-backdrop-filter` in the list:
```css
.foo {
  transition-property: -webkit-backdrop-filter, backdrop-filter;
}
```

Then it compiles to:
```css
.foo {
  transition-property: -webkit-backdrop-filter, -webkit-backdrop-filter, backdrop-filter;
}
```

This is not what we want. So in this case, whenever a non-prefixed
property is found in the list (`backdrop-filter`), then we can remove or
ignore all prefixed values. Once we are printing the CSS back, the
`backdrop-filter` will print the prefixed version as well.

```css
.foo {
  transition-property: -webkit-backdrop-filter, backdrop-filter;
}
```
RobinMalfait added a commit to tailwindlabs/tailwindcss that referenced this pull request Nov 6, 2024
This PR improves the generated CSS by running it through Lightning CSS
twice.Right now Lightning CSS merges adjacent at-rules and at the end
flattens the nesting. This means that after the nesting is flattened,
the at-rules that are adjacent and could be merged together will not be
merged.

This PR improves our output by running Lightning CSS twice on the
generated CSS which will make sure to merge adjacent at-rules after the
nesting is flattened.

Note: in the diff output you'll notice that some properties are
duplicated. These need some fixes in Lightning CSS itself but they don't
break anything for us right now.

Related PR in Lightning CSS for the double `-webkit-backdrop-filter` can
be found here: parcel-bundler/lightningcss#850

---------

Co-authored-by: Philipp Spiess <hello@philippspiess.com>
@devongovett
Copy link
Member

devongovett commented Nov 25, 2024

Thanks, and sorry for the delay on review. I updated this to handle a couple more cases:

  • If there are properties without an unprefixed value, we should still merge duplicates. This is done by merging any properties that have the same value minus the prefix (by setting it to empty). This should theoretically also be faster than comparing the string names of properties.
  • We also need to handle merging the transition shorthand, which is not automatically handled in the same place.

@devongovett devongovett merged commit 33265a2 into parcel-bundler:master Nov 25, 2024
3 checks passed
@LeoniePhiline
Copy link
Contributor

I also made sure that the original author is marked as a co-author.

Very kind – thank you! ❤️

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.

Already prefixed backdrop-filter results in two prefixed declarations
3 participants