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-env to 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

Comments

lauriii created an issue. See original summary.

lauriii’s picture

Status: Active » Needs review
StatusFileSize
new712.88 KB

Here's first patch which is configure to polyfill stage 1 drafts. This is based on what Olivero would need.

lauriii’s picture

FWIW, I believe we could have used postcss-preset-env in #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.

lauriii’s picture

StatusFileSize
new704.63 KB

Patch in #2 had some unrelated changes.

mherchel’s picture

Status: Needs review » Needs work

+1 to this from the Olivero theme's point of view!

+++ b/core/scripts/css/compile.js
@@ -2,29 +2,20 @@ const chalk = require('chalk');
+      postcssPresetEnv({ stage: 1 }),

Should we add preserve: false to 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/...)

lauriii’s picture

Status: Needs work » Needs review
StatusFileSize
new47.24 KB
new668.17 KB

Good idea! Enabling the preserve setting significantly reduces the patch size. 👍

mherchel’s picture

Status: Needs review » Needs work

This is looking good! Seems like there's some invalid CSS going on in tabledrag, though.

+++ b/core/themes/claro/css/components/tabledrag.css
@@ -321,14 +321,12 @@ body.drag {
+@medianot all and (min-resolution: 0.001dpcm) and {

This looks invalid. Not sure what's going on. We might need to rewrite that CSS file.

mherchel’s picture

FWIW, the previous CSS looks invalid too.

bnjmnm’s picture

  1. I was not able to get this working locally without adding the @babel/runtime dependency. 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. Same issue with HEAD
  2. +++ b/core/themes/claro/css/components/details.css
    @@ -250,13 +247,11 @@ rgba(0, 0, 0, 0.1);
    -}
    

    It looks like the needed double media query used for targeting Safari is removed on compile now.

  3. From the looks of yarn.lock this adds several new dependencies so (based on several other issues I've been working on), an evaluation needs to be provided for each.
lauriii’s picture

Status: Needs work » Needs review
StatusFileSize
new48.11 KB
new1.91 KB

This 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?

bnjmnm’s picture

Could you post the error that you are seeing and which command did you run when that error appeared?

The error was Error: Cannot find module '@babel/runtime/helpers/interopRequireWildcard' Same issue with HEAD, not specific to this change. Created followup issue for that bug #3172253: build:css error regarding missing interopRequireWildcard

alexpott’s picture

  1. +++ b/core/themes/claro/css/base/elements.css
    @@ -57,23 +57,7 @@
     html {
    -  font-family: BlinkMacSystemFont
    -,
    --apple-system
    -,
    -"Segoe UI"
    -,
    -Roboto
    -,
    -Oxygen-Sans
    -,
    -Ubuntu
    -,
    -Cantarell
    -,
    -"Helvetica Neue"
    -,
    -sans-serif;
    +  font-family: BlinkMacSystemFont, -apple-system, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    

    These changes are a nice result - much more readable and less bytes to send too :)

  2. +++ b/core/themes/claro/css/components/details.css
    @@ -404,13 +401,11 @@ rgba(0, 0, 0, 0.1);
     /* stylelint-disable-next-line unit-whitelist */
     
    -@media not all and (min-resolution: 0.001dpcm) {
    -  @media {
    +@medianot all and (min-resolution: 0.001dpcm) and {
         .claro-details__summary::after {
           transition: none;
         }
       }
    -}
     
    

    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 :)

  3. +++ b/core/themes/claro/css/components/system-admin--links.css
    @@ -35,6 +35,6 @@ small .admin-link:after {
     .system-cron-settings__link {
    -  overflow-wrap: break-word;
    +  word-wrap: break-word;
       word-wrap: break-word;
     }
    

    This change looks interesting. At the very least now we have duplicated word-wrap: break-word;

  4. +++ b/core/themes/claro/css/components/views-ui.css
    @@ -431,6 +431,7 @@ details.fieldset-no-legend {
    +  border-right: 0;
       border-right: initial;
    
    @@ -471,6 +472,7 @@ details.fieldset-no-legend {
    +  border-right: 0;
       border-right: initial;
    

    these look interesting as border-right is defined twice.

lauriii’s picture

StatusFileSize
new48.67 KB
new2.11 KB

Thank 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.

mherchel’s picture

Status: Needs review » Needs work
+++ b/core/scripts/css/compile.js
@@ -2,29 +2,22 @@ const chalk = require('chalk');
+        stage: 1,

I'm working on refactoring Olivero to support postcss-preset-env, and ran into an issue with the postcss-focus-within plugin. (Olivero uses focus-within with non-js fallbacks).

The way that it works is that it sets the :focus-within pseudo-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

      postcssPresetEnv({
        stage: 1,
        preserve: false,
        autoprefixer: { grid: 'no-autoplace' },
        features: {
          'focus-within-pseudo-class': false
        }
      }),
mherchel’s picture

I 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).

mherchel’s picture

I 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.

lauriii’s picture

Status: Needs work » Needs review
StatusFileSize
new48.26 KB
new43 KB
new5.69 KB

Rerolled #13 and disabled plugins listed in #15.

alexpott’s picture

Status: Needs review » Needs work
+++ b/core/themes/claro/css/components/system-admin--links.css
@@ -35,6 +35,6 @@ small .admin-link:after {
 .system-cron-settings__link {
-  overflow-wrap: break-word;
+  word-wrap: break-word;
   word-wrap: break-word;
 }

Twice the word-wrap fun :)

lauriii’s picture

Status: Needs work » Needs review
StatusFileSize
new43.42 KB
new627 bytes

Seems like something went wrong with the reroll 😅

mherchel’s picture

Status: Needs review » Needs work

This 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' or grid: '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!)

lauriii’s picture

Status: Needs work » Needs review
StatusFileSize
new44.2 KB
new1.28 KB

Added grid: 'no-autoplace' for now. In future, we can look into why the autoplace is not working if it's something that we need.

lauriii’s picture

Issue summary: View changes
lauriii’s picture

Issue summary: View changes

Added dependency evaluation.

lauriii’s picture

Issue summary: View changes
mherchel’s picture

Status: Needs review » Reviewed & tested by the community

Code looks good from the Olivero standpoint!

catch’s picture

This looks fine to me from a release-management point of view - swapping one dev-only package for another one.

xjm’s picture

I 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.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 611923c and pushed to 9.1.x. Thanks!

Fixed spelling on commit.

diff --git a/core/misc/cspell/dictionary.txt b/core/misc/cspell/dictionary.txt
index 49e1153359..60bf595626 100644
--- a/core/misc/cspell/dictionary.txt
+++ b/core/misc/cspell/dictionary.txt
@@ -109,6 +109,7 @@ autoloader
 autoloaders
 autoloading
 autop
+autoplace
 autoplay
 autoreply
 autosave

Due to /Users/alex/dev/drupal/core/scripts/css/compile.js:38:21 - Unknown word (autoplace)

  • alexpott committed 611923c on 9.1.x
    Issue #3170864 by lauriii, mherchel, bnjmnm, alexpott, xjm, catch: Add...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

xjm’s picture

Issue tags: +9.1.0 release notes