Problem/Motivation
Claro uses PostCSS for converting modern CSS into CSS that older browsers understand. Claro is mainly utilizing this for CSS custom properties. There are many other modern CSS features that would increase the frontend developer experience and speed up the development.
Proposed resolution
Add postcss-preset-env and remove our dependency on postcss-custom-properties. This would be similar approach to JavaScript where we use babel preset-env.
Dependency evaluation
- Maintainership of the package: latest commit on the repository was in 28 Apr 2020. Mainly maintained by a single person who seems to be still active https://github.com/csstools/postcss-preset-env/issues/191
- License: CC0 1.0 Universal
- Security policies of the package: Not formally documented. This library is only used in by core developers in development environments.
- Expected release and support cycles: undocumented; seems like new major releases are being released with similar cadence to PostCSS. Only single major release is supported at the time.
- Code quality: well documented, comprehensive tests.
- Other dependencies it would add, if any: list of additional dependencies.
Remaining tasks
- Decide which stage to configure
postcss-preset-envto polyfill.
User interface changes
-
API changes
Commands used for compiling CSS remain the same. This only impacts how CSS is compiled behind the scenes.
Data model changes
None
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #21 | interdiff.txt | 1.28 KB | lauriii |
| #21 | 3170864-21.patch | 44.2 KB | lauriii |
| #19 | interdiff.txt | 627 bytes | lauriii |
| #19 | 31708640-19.patch | 43.42 KB | lauriii |
| #17 | interdiff.txt | 5.69 KB | lauriii |
Comments
Comment #2
lauriiiHere's first patch which is configure to polyfill stage 1 drafts. This is based on what Olivero would need.
Comment #3
lauriiiFWIW, I believe we could have used
postcss-preset-envin #3060153: Use PostCSS in core, initially only for Claro. I think it's a better solution for using PostCSS as a polyfill for modern CSS.Comment #4
lauriiiPatch in #2 had some unrelated changes.
Comment #5
mherchel+1 to this from the Olivero theme's point of view!
Should we add
preserve: falseto the config? This setting will remove the CSS Custom Properties instead of including both the custom property and the transpiled value (which is what core currently does - see https://git.drupalcode.org/project/drupal/-/blob/9.0.x/core/scripts/css/...)Comment #6
lauriiiGood idea! Enabling the preserve setting significantly reduces the patch size. 👍
Comment #7
mherchelThis is looking good! Seems like there's some invalid CSS going on in tabledrag, though.
This looks invalid. Not sure what's going on. We might need to rewrite that CSS file.
Comment #8
mherchelFWIW, the previous CSS looks invalid too.
Comment #9
bnjmnmwas not able to get this working locally without adding theSame issue with HEAD@babel/runtimedependency. I'm on a brand new machine, so it's possible it's specific to my new-and-trying local env, but would be good for another reviewer to confirm this.It looks like the needed double media query used for targeting Safari is removed on compile now.
Comment #10
lauriiiThis should address #7. The invalid CSS is being used for targeting some rules specifically for Safari.
#9.1: Could you post the error that you are seeing and which command did you run when that error appeared?
Comment #11
bnjmnmThe error wasSame issue with HEAD, not specific to this change. Created followup issue for that bug #3172253: build:css error regarding missing interopRequireWildcardError: Cannot find module '@babel/runtime/helpers/interopRequireWildcard'Comment #12
alexpottThese changes are a nice result - much more readable and less bytes to send too :)
This change doesn't look correct and like the other similar changes later on and above. But I'm not a CSS expert - might be legit :)
This change looks interesting. At the very least now we have duplicated
word-wrap: break-word;these look interesting as border-right is defined twice.
Comment #13
lauriiiThank you for the review @alexpott!
#12.2 was supposed to be addressed by #10 but seems like I missed one more instance of this.
#12.3 Addressed this by removing word-wrap from the source file. The word-wrap property was originally a nonstandard and unprefixed IE extension, and was implemented by most browsers with the same name. It has since been renamed to overflow-wrap, with word-wrap being an alias.
#12.3 IE doesn't support initial so I guess the border-right: 0 is correct assumption on what the initial value could be. I tested this before and after with both, IE 11 and Chrome and didn't notice any visual differences.
Comment #14
mherchelI'm working on refactoring Olivero to support
postcss-preset-env, and ran into an issue with thepostcss-focus-withinplugin. (Olivero usesfocus-withinwith non-js fallbacks).The way that it works is that it sets the
:focus-withinpseudo-class to a[focus-within]attribute, which then needs to be paired with a JS polyfill to make that happen.I recommend disabling this plugin, and also going through the list of plugins (https://github.com/csstools/postcss-preset-env/blob/master/src/lib/plugi...) to disable all that require a polyfill (looks like there may be several).
Here is my current setup in compile.js
Comment #15
mherchelI did a little bit of looking through the dependencies, and the following PostCSS plugins require JS polyfills to work. I recommend disabling each of these (unless we choose to utilize the JS polyfill also).
Comment #16
mherchelI committed the (almost) final and largest chunk of refactoring Olivero to use PostCSS Preset ENV this morning.
I also wrote a first draft of documentation at https://www.drupal.org/docs/contributed-themes/olivero/authoring-css-for..., that we can use as a starter for core docs.
Comment #17
lauriiiRerolled #13 and disabled plugins listed in #15.
Comment #18
alexpottTwice the word-wrap fun :)
Comment #19
lauriiiSeems like something went wrong with the reroll 😅
Comment #20
mherchelThis looks really close!
We also need to turn on CSS Grid support for IE11 (Olivero uses CSS Grid extensively). CSS Grid is disabled by default in Autoprefixer (see https://github.com/postcss/autoprefixer/blob/master/README.md#options), and can be turned on by setting either
grid: 'autoplace'orgrid: 'no-autoplace'. The autoplacement feature didn't work for us, so have the latter option set.I should've explicitly mentioned this in my previous comment (sorry!)
Comment #21
lauriiiAdded
grid: 'no-autoplace'for now. In future, we can look into why the autoplace is not working if it's something that we need.Comment #22
lauriiiComment #23
lauriiiAdded dependency evaluation.
Comment #24
lauriiiComment #25
mherchelCode looks good from the Olivero standpoint!
Comment #26
catchThis looks fine to me from a release-management point of view - swapping one dev-only package for another one.
Comment #27
xjmI was a little concerned at first that we were switching from a babel package to just some individual maintainer's, but per @lauriii we were already relying on him for the other dep changed in this release, so that seems OK to me.
I did suggest posting some of the open dep evaluation questions in their queue so we have it for future reference, but I don't think it needs to block this going in.
Comment #28
alexpottCommitted 611923c and pushed to 9.1.x. Thanks!
Fixed spelling on commit.
Due to
/Users/alex/dev/drupal/core/scripts/css/compile.js:38:21 - Unknown word (autoplace)Comment #31
xjm