Make WordPress Core

Opened 21 months ago

Closed 4 weeks ago

#63013 closed enhancement (fixed)

Twenty Nineteen: Use `sass` instead of `node-sass`

Reported by: debarghyabanerjee Owned by: wildworks
Priority: normal Milestone: 7.2
Component: Bundled Theme Version:
Severity: normal Keywords: has-patch
Cc: Focuses: javascript, css

Description

node-sass is deprecated and no longer maintained. We should switch to sass, the official and actively supported Sass compiler, to stay up-to-date with the latest features and improvements.

Change History (31)

This ticket was mentioned in ​PR #8404 on ​WordPress/wordpress-develop by ​@debarghyabanerjee.


21 months ago
#1

  • Keywords has-patch added; needs-patch removed

Trac Ticket: Core-63013

### Summary

This PR replaces node-sass with sass in the twentynineteen theme. node-sass is deprecated and no longer maintained, while sass is the official, actively supported implementation of Sass.

This ticket was mentioned in ​PR #8405 on ​WordPress/wordpress-develop by ​@debarghyabanerjee.


21 months ago
#2

Trac Ticket: Core-63013

### Summary

This PR replaces node-sass with sass in the twentynineteen theme. node-sass is deprecated and no longer maintained, while sass is the official, actively supported implementation of Sass.

#3 @sabernhardt
21 months ago

  • Component Themes → Bundled Theme
  • Summary Update: Use `sass` instead of `node-sass` in twentynineteen theme → Twenty Nineteen: Use `sass` instead of `node-sass`

@sainathpoojary also ​reported the deprecation on GitHub.

If the package switches to sass:

  • The output is very different, especially with the order of language-specific selectors. Setting up some linting rules could help (for example, with stylelint-config).
  • Please use --no-source-map. Twenty Nineteen does not have the .map files yet, and committing one change with the source maps could require refreshing any other pull requests that were made with older map files.

#4 follow-up: @debarghyabanerjee
21 months ago

  • Component Bundled Theme → Themes

Hi @sabernhardt,

  1. I have added the --no-source-map
  1. Do you suggest any specific linting rules that should be added in the stylelint-config?

#5 in reply to: ↑ 4 @sabernhardt
21 months ago

  • Component Themes → Bundled Theme

Do you suggest any specific linting rules that should be added in the stylelint-config?

Unfortunately, I do not know linting rules well. Some of the rules for Twenty Twenty-One could also fit Twenty Nineteen.

Of course, my reason for mentioning stylelint-config is to avoid so many changes in the compiled output. A few of the differences should be good, but others surprised me.

  • The sass output ignores five of the selectors when it creates font overrides for each non-latin language: .not-found .page-title, .error-404 .page-title, input[type="button"], input[type="reset"], and input[type="submit"]. That was difficult to notice because the compiler rearranges the lists of language selectors.
  • The #005177 blue becomes rgb(0, 80.5, 119), slightly reducing its green value.
  • Many empty lines between rulesets are removed, but not all of them consistently.
  • Some comma-separated selectors share a line, where node-sass had given each its own line.

I should also point out that Dart Sass gives dozens of deprecation warnings when running the build, so switching to it would require additional changes soon.

This ticket was mentioned in ​PR #12156 on ​WordPress/wordpress-develop by ​@desrosj.


5 months ago
#6

This replaces node-sass with sass (Dart Sass).

Looking into the issues raised on the Trac ticket, here is some output from Claude around each one.

The sass output ignores five of the selectors when it creates font overrides for each non-latin language: .not-found .page-title, .error-404 .page-title, input[type="button"], input[type="reset"], and input[type="submit"]. That was difficult to notice because the compiler rearranges the lists of language selectors.

This appears to be caused by the redundancy elimination part of Dart Sass related to the use of @extend.

<details>
<summary>Full output from Claude: Output ignores five of the selectors when it creates font overrides for each non-latin language</summary>

How the SCSS builds the non-latin overrides:

  // sass/mixins/_mixins-master.scss
  %non-latin-fonts {
    @each $lang, $font__fallback in $font__fallbacks {
      &:lang(#{$lang}) { font-family: unquote($font__fallback); }
    }
  }

  @mixin font-family($font_family: $font__body) {
    font-family: $font_family;
    @extend %non-latin-fonts;
  }

  Every selector list that calls @include font-family(...) gets @extended into the placeholder, producing one giant
  <every-selector>:lang(ar) { ... } rule per language. LibSass emitted that list verbatim. Dart Sass runs a "redundancy
  elimination" pass on extend results — if one selector in the merged list is a structural superselector of another
  (matches a superset of elements), the more specific one is dropped.

  For the .page-title cases this is provably what happened. In sass/typography/_headings.scss:

  - Lines 11/33/75/144 include .not-found .page-title and .error-404 .page-title in lists that @include font-family(...).
  - Line 54: .page-title { @include font-family($font__body); } — bare .page-title is also extended.

  So .page-title:lang(ar) is already in the merged list, and Dart Sass treats .not-found .page-title:lang(ar) and
  .error-404 .page-title:lang(ar) as redundant subselectors and drops them.

  The three input[type=...] cases come from sass/forms/_buttons.scss:

  .button, button, input[type="button"], input[type="reset"], input[type="submit"] {
    @include font-family($font__heading);
  }

  The bare button element is in the same list. Dart Sass's selector-unification math considers
  input[type="button"]:lang(ar) covered by other selectors in the merged result and trims them too — button:lang(ar) is
  the most likely cause here as the trimmer can over-eagerly treat attribute-restricted versions of an element selector as
   redundant when both end up in the same combined list.

  This is a real change in matched elements:
  - .not-found .page-title:lang(ar) is fine — .page-title:lang(ar) does match it, so the font fallback still applies via
  the kept selector. (No visual regression.)
  - input[type="button"]:lang(ar) etc. — these are only covered if you accept that button:lang(ar) covers them, but a
  <input type="submit"> is not a <button> element. So Arabic/Hebrew/etc. submit buttons would lose the non-latin font
  fallback. That is a real visual regression.

  The fix is to refactor the mixin away from @extend. Either:

  @mixin font-family($font_family: $font__body) {
    font-family: $font_family;
    @each $lang, $font__fallback in $font__fallbacks {
      &:lang(#{$lang}) { font-family: unquote($font__fallback); }
    }
  }

  This emits the same rules inline at every call site (slightly more CSS in bytes, no extend trimming, output is stable).
  Or keep @extend but split the placeholder into per-language placeholders. The inline @each is simpler and idiomatic for
  current Sass.

</details>

The #005177 blue becomes rgb(0, 80.5, 119), slightly reducing its green value.

This one seems to be caused by lighten()/darken(), which have been deprecated. I've gone and hard coded the intended hex values to address this for now.

<details>
<summary>Full output from Claude: Why are hexidecimal colors output as rgb() and slightly different?</summary>

These come from the lighten()/darken() calls the deprecation warnings flagged in _comments.scss:240 and elsewhere. The

math:

  • $colorlink = #0073aa = rgb(0, 115, 170)
  • darken($colorlink, ~8%) round-trips through HSL.
  • LibSass clamped/rounded the resulting RGB channels to integers and emitted hex.
  • Dart Sass keeps fractional precision and emits rgb(0, 80.5, 119) rather than #005177.

Browsers accept fractional rgb() (CSS Color L4), so the rendered color is rgb(0, 80.5, 119) — half a step off the prior
rgb(0, 81, 119). Imperceptible visually, but technically not byte-identical and slightly off from what the designer
presumably intended (#005177).

The right fix is the same as resolving the deprecation: replace lighten()/darken() calls with the intended literal hex
(best — that's what the designer originally meant), or wrap with color.adjust() which is the modern API. As a stopgap
you can wrap with round() to coerce channels back to integers.

`
</details>

Many empty lines between rulesets are removed, but not all of them consistently.

While annoying, this one does not require any action. It's just a formatting issue.

From Claude:

Dart Sass's expanded formatter inserts blank lines around rule boundaries based on its own heuristics (e.g., always after @font-face, between top-level rules, but not consistently between sibling rules that came from a @for/@each loop). It does not preserve blank lines from your .scss source. There's no flag to make it match LibSass's "preserve source whitespace" behavior — this is just the formatter, and the inconsistency is baked in.

Some comma-separated selectors share a line, where node-sass had given each its own line.

Claude output:

As noted before, this is the @extend merge grouping. Dart Sass joins selectors that came from the same extend operation with , on a single line and uses ,\n between groups; LibSass put every selector on its own line unconditionally. No formatter flag.

After pushing a bit further, I had it create a small PostCSS plugin to enforce this.

Trac ticket: Core-63013.

## Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Opus 4.7
Used for: Researching the reasons behind the differences in built files after updating.

#7 @desrosj
5 months ago

  • Milestone Awaiting Review → 7.1

This appears to be a blocker for upgrading the version of Node.js from 20.x to 24.x in #65451.

I've created a new PR attempting to address some of the items called out by @sabernhardt above.

I have not yet reviewed the resulting changes past a cursory glance.

This ticket was mentioned in ​Slack in #core by adrianduffell. ​View the logs.


4 months ago

#9 @adrianduffell
4 months ago

This looks worth prioritizing to unblock Node 24. Does it need to be completed before the 7.1 beta? If so, it has a chance to be included if the PR can be reviewed in the coming days.

Last edited 4 months ago by adrianduffell (previous) (diff)

​adrianduffell commented on ​PR #12156:


4 months ago
#10

@desrosj is this ready for review?

This ticket was mentioned in ​PR #12510 on ​WordPress/wordpress-develop by ​@sabernhardt.


4 months ago
#11

Co-authored by @desrosj

  • Replaces node-sass with sass in package, and updates the build scripts.
  • Replaces lighten(), darken(), and mix() with the previously computed color values.
  • Creates a new mixin for non-latin fonts so the Sass can still use @extend for 76 of the 81 selectors in style.css (and style-rtl.css) and 30 of 33 selectors in style-editor.css.
  • Adds the remaining selectors below their related rulesets with the new mixin.
  • Moves comments—or changes their syntax to //—so they do not print in an unrelated place, such as
    .main-navigation {
      /* Un-style buttons */
    }
    

Trac 63013

## Use of AI Tools

This is built on ​https://github.com/WordPress/wordpress-develop/pull/12156, which involved Claude and Copilot, but I did not use AI in addition to that.

​@sabernhardt commented on ​PR #12510:


4 months ago
#12

GitHub Desktop told me the compiled stylesheets changed line endings to CRLF, but I saw them as LF in my file editor. I edited the .scss files in the browser, so they should have the correct line endings.

This ticket was mentioned in ​Slack in #core by adrianduffell. ​View the logs.


4 months ago

#14 @adrianduffell
4 months ago

  • Milestone 7.1 → Future Release

This was discussed in today's bug scrub. I was hoping it could make it in 7.1, but with the beta being released in the coming hours, we will have to punt. It would be good to pick up again in 7.2.

#15 @wildworks
4 months ago

  • Milestone Future Release → 7.2

#16 @karmatosed
2 months ago

  • Keywords needs-testing added

I would love to get this in, but I feel like we need testing of this against not just this theme when we do get it in. For example, a flag raised is that this could impact other themes. Lets see what we can do about getting that and then get this in earlier in cycle hopefully this time.

This ticket was mentioned in ​Slack in #core-test by jina_parekh. ​View the logs.


6 weeks ago

#18 @cyrusblake89
6 weeks ago

Tested the patch on Windows 11 using WordPress Studio running trunk.

Installed npm and updated package.json to use sass instead.

Compiled stylesheets with npm run build and then activated Twenty Nineteen on my local site to verify changes.

#19 @wildworks
5 weeks ago

There are currently three open PRs for this ticket:

  1. ​https://github.com/WordPress/wordpress-develop/pull/8405
  2. ​https://github.com/WordPress/wordpress-develop/pull/12156
  3. ​https://github.com/WordPress/wordpress-develop/pull/12510

I would like to close #1 and #2 and move forward with #3. It addresses all the issues raised in comment:5, and it has the smallest CSS diff, which should make it easier to review and regression test.

Now that Core has been updated to Node.js 24.x in [63539], Twenty Nineteen and Twenty Twenty (see #66004) are the only bundled themes not yet on Node.js 24.x, and this ticket is what blocks Twenty Nineteen from moving to it.

I'd like to refresh #3 against trunk and also bump the theme's Node.js version to 24.x.

​@wildworks commented on ​PR #8405:


5 weeks ago
#20

Closing in favor of #12510. Thank you for your work on this!

---
_Generated by ​Claude Code_

​@wildworks commented on ​PR #12156:


5 weeks ago
#21

Closing in favor of #12510. Thank you for your work on this!

---
_Generated by ​Claude Code_

​@wildworks commented on ​PR #12510:


5 weeks ago
#22

I've refreshed this PR and bumped the Node version to 24.

​@wildworks commented on ​PR #12510:


5 weeks ago
#23

As a minor improvement, I added the devEngines field, similar to Twenty Twenty-One.\

#24 @wildworks
5 weeks ago

  • Keywords commit added

I ran a thorough visual regression test with the help of AI, comparing the front end with the current trunk CSS and this PR's CSS. All 310 screenshots matched pixel for pixel, so this PR should not introduce any visual regressions.

I believe ​https://github.com/WordPress/wordpress-develop/pull/12510 is ready to merge, but any additional feedback is welcome. Please let us know if there are any issues.

​@rejaulalomkhan commented on ​PR #12510:


5 weeks ago
#25

Thanks for refreshing this, @t-hamano and @sabernhardt! Building on @t-hamano's front-end screenshots, I tested the parts listed there as "Not covered": the editor styles and hover/focus states.

Patch Testing Report

Patch tested: ​https://github.com/WordPress/wordpress-develop/pull/12510 (head 64c7e80)

Environment

  • WordPress: 7.2-alpha-63166-src (wordpress-develop Docker environment)
  • PHP: 8.3.35
  • Server: nginx (wordpress-develop Docker environment)
  • Database: MySQL 8.4.11
  • Browser: Chromium 149 headless (Playwright 1.61.1), deviceScaleFactor: 1, reduced motion
  • OS: macOS
  • Theme: Twenty Nineteen
  • Build: Node 24.18.1, sass 1.101.0
  • MU Plugins: None activated
  • Plugins: None activated

Steps taken

  1. Ran npm ci and npm run build in the PR's twentynineteen folder → style.css, style-rtl.css, style-editor.css, style-editor-customizer.css and print.css are byte-identical to the committed files, and stay identical over 3 more builds.
  2. Created a post with headings 1–6, drop cap, inline formatting, lists, quotes (default and large), pullquote, fill and outline buttons, table, code, preformatted, verse, separators, columns, group, cover, latest posts, archives, categories and search, plus a primary menu with a submenu.
  3. Took screenshots with trunk's compiled CSS and with the PR's compiled CSS, comparing exact pixels:
    • the full block editor canvas (style-editor.css), 1280px wide;
    • rest, hover and keyboard focus of a content link, both buttons, the search button, the site title and post navigation, at 1280px and 375px;
    • the open submenu on hover, and the first 8 Tab stops from the top of the page at both widths.
  4. Ran trunk twice to rule out noise (54/54 identical), then a control with three deliberate CSS changes (editor h2 color, menu hover color, link focus outline) → exactly those 4 screenshots changed, so the comparison catches small differences.
  5. ✅ Patch is solving the problem: with the PR's CSS, all 54 screenshots match trunk pixel for pixel, including the editor canvas and every hover and focus state tested.

Expected result

  • Switching from node-sass to sass causes no visual change in the editor or in interactive states.

Additional Notes

  • Not from this PR, but "build": "run-p \"build:*\"" runs build:rtl in parallel with build:style, so rtlcss can read the old style.css. After changing $color__background-body and running npm run build once, style.css had the new color and style-rtl.css did not; a second build fixed it. Trunk has the same run-p setup. Twenty Twenty-One uses run-s; with "build": "run-s \"build:*\"" one build updates both files (about 4s instead of 2s). Since the PR already touches these scripts, it could switch to run-s, or that could be a follow-up.
  • The build prints Sass deprecation warnings (@import, / division, global built-in functions; 20 shown, 38 more omitted). They don't affect the output today; the module system migration could be a follow-up.
  • AI assistance: Claude Code was used to run the build and the screenshot comparison; results reviewed by me.

​@wildworks commented on ​PR #12510:


5 weeks ago
#26

Since 7.2 Beta 1 is scheduled to be released next week, I will commit this beforehand. If anyone finds any issues, please feel free to report them.

#27 @wildworks
5 weeks ago

  • Owner set to wildworks
  • Resolution → fixed
  • Status new → closed

In 64387:

Twenty Nineteen: Replace node-sass with sass

Twenty Nineteen now compiles its stylesheets with the actively maintained sass package instead of the deprecated node-sass, which allows the theme to move to Node.js 24.x without changing the compiled CSS output.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/12510

Props adrianduffell, cyrusblake89, debarghyabanerjee, desrosj, karmatosed, rejaulalomkhan, sabernhardt, sainathpoojary, wildworks.

Fixes #63013.

This ticket was mentioned in ​PR #14549 on ​WordPress/wordpress-develop by ​@sabernhardt.


4 weeks ago
#28

Co-authored by @rejaulalomkhan

  • Updates package-lock.json after npm audit fix and npm dedupe (which might be done with other npm updates anyway).
  • Changes the build to run each command sequentially, so npm run build does not need to be used twice to update the RTL stylesheet.
  • Introduces sass:string to prevent deprecation warnings for unquote() global built-in.
  • Uses math.div() to prevent deprecation warnings for slash-div calculations.
  • Does not replace @import (yet).

Trac 63013

Use of AI Tools

none by me

​@sabernhardt commented on ​PR #14549:


4 weeks ago
#29

​Replacing `@import` is not included in this PR because that is much more involved than the rest.

#30 @sabernhardt
4 weeks ago

  • Keywords needs-testing commit removed
  • Resolution fixed
  • Status closed → reopened

Reopening to consider a small follow-up commit.

#31 @SergeyBiryukov
4 weeks ago

  • Resolution → fixed
  • Status reopened → closed

In 64610:

Twenty Nineteen: Adjust sass usage.

This commit:

  • Updates package-lock.json after npm audit fix and npm dedupe (which might be done with other npm updates anyway).
  • Changes the build to run each command sequentially, so npm run build does not need to be used twice to update the RTL stylesheet.
  • Introduces sass:string to prevent deprecation warnings for unquote() global built-in.
  • Uses math.div() to prevent deprecation warnings for slash-div calculations.
  • Does not replace @import (yet).

Developed in ​https://github.com/WordPress/wordpress-develop/pull/14549.

Follow-up to r64387.

Props sabernhardt, rejaulalomkhan.
Fixes #63013.

Note: See TracTickets for help on using tickets.