-
Notifications
You must be signed in to change notification settings - Fork 114
implement supports conditions
#548
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
implement supports conditions
#548
Conversation
supports conditions
RyanZim
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to clarify, base64 encoding is only used for external URL imports, right?
A few questions below as well; otherwise, looks good.
|
Thank you for the review 🙇
Yes. |
|
Thanks a lot! Ready to publish as v16? |
|
I think I'll wait until after the New Year to publish, just in case something goes wrong. |
|
025f27a 🎉 |
|
Awesome! thank you so much for all the careful reviews 🙇 |
supersedes : #532
fixes : #529
The core issue is how multiple statements are combined.
The previous implementation tried to squash media queries and layer conditions.
layer(foo) screenlayer(bar) (min-width: 1000px)becomes :
In this example the
foolayer is only defined when the media isscreenand has a width of1000px. While it should actually be defined even when the media isscreenand smaller.screennot printbecomes :
In this example the media query becomes invalid because
andcan not be used to combinescreenandnot printThe implementation for this feature was also fairly complex.
Adding
supportsinto this would have made the implementation very unwieldy and it would have increased the chance that users experience bugs.The correct way to combine is actually much simpler.
layer(foo) screenlayer(bar) (min-width: 1000px)becomes :
screennot printbecomes :
By using nested statements we ensure that the order of declaration is respected and that no invalid statements are produced.
At this point it also becomes trivial to add support for
supportsconditions.This method does break one aspect.
@importstatements can not be nested syntactically in CSS.They must appear first at the root of the AST.
valid :
invalid :
To restore support for this we can use nested stylesheets.
@importstatement urls can be base64 encoded data urls.This doesn't actually have to be base64 encoded, but encoding makes it less prone to errors.
Without encoding it looks like this :
@imports url('http://something-external.com') not print;screenmedia conditionThis technique was first thought of by the maintainer of esbuild while fixing issues brought to light by https://github.com/romainmenke/css-import-tests
This implementation change fixes a lot of subtle bugs and as far as I can tell the output is almost always smaller.
It also eliminates some complexity for users.
They no longer need to define things like
nameLayerfor anonymous layers to work correctly. The issue for which we introduced that option no longer exists in this implementation.So I think this is a pure win :)