Skip to content

chore: Update Sass Library - #55304

Merged
noahtallen merged 7 commits into
trunkfrom
update/sass-with-deprecation-warn
Aug 24, 2021
Merged

noahtallen merged 7 commits into
trunkfrom
update/sass-with-deprecation-warn

Conversation

@noahtallen

@noahtallen noahtallen commented Aug 10, 2021 •

Copy link
Copy Markdown
Contributor

Changes proposed in this Pull Request

  1. Update dependency sass to 1.37.5 and sass-loader to 12.1.0.
  2. Run sass-migrator division across the codebase
  3. Change our webpack sass prelude to use @use instead of @import
  4. Hide deprecation warnings from dependencies.

This PR is motivated by #54793. Specifically, the new wp monorepo update also updates the version of sass. The new version of sass includes a deprecation warning for the division operator (/). More info on that here. This deprecation warning prints thousands of times during the build process and I even got a segfault running the build which miiiight be related. It also fills the TeamCity build log until it reaches the log limit, so we can't see any actual problems with the build, just the dep warning. As a result, we can't really merge that update without resolving this deprecation warning.

DEPRECATION WARNING: Using / for division is deprecated and will be removed in Dart Sass 2.0.0.

Recommendation: math.div($pixels, $context)

More info and automated migrator: https://sass-lang.com/d/slash-div

Thankfully, sass has a migrator tool which lets us auto-fix this problem.

However, that raises a different problem, which is that all @use directives must be the very first thing in the file. The new division operator is imported via @use:

ERROR in ../packages/design-picker/src/components/style.scss
Module build failed (from ../node_modules/mini-css-extract-plugin/dist/loader.js):
ModuleBuildError: Module build failed (from ../node_modules/sass-loader/dist/cjs.js):
SassError: @use rules must be written before any other rules.
   |
 2 │ @use 'sass:math';
   | ^^^^^^^^^^^^^^^^
   |
 packages/design-picker/src/components/style.scss 2:1  root stylesheet

I discovered the culprit, which is our prelude (additionalData) which is added to every sass file in the project. It basically means that an import statement is inserted as first thing in every file instead of the use statement. Thankfully, this can be migrated to the new format like so:

- @import 'path/to/_utils.scss';
+ @use 'path/to/_utils.scss' as *;

The as * defines the namespace for the import. Without it, you'd have to start referencing variables with the namespace prefixed. While that sounds like a good idea to implement in the long run, we have hundreds of references to these variables which assume they are defined globally. As such, we need to continue defining them globally with the * namespace.

Finally, I also needed to set the quietDeps flag in our sass options. This flag disables deprecation warnings when processing imported/3rd-party stylesheets. This is important, as we can't fix those deprecation warnings ourselves, and it adds so much noise to the build log that TeamCity can't display the entire logfile.

Testing instructions

  • Smoke test stylesheets across the codebase
  • CI should pass

@noahtallen
noahtallen requested review from a team as code owners August 10, 2021 02:16
@matticbot matticbot added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Aug 10, 2021
@github-actions

github-actions Bot commented Aug 10, 2021 •

Copy link
Copy Markdown

@matticbot

Copy link
Copy Markdown
Contributor

This PR modifies the release build for editing-toolkit

To test your changes on WordPress.com, run install-plugin.sh editing-toolkit update/sass-with-deprecation-warn on your sandbox.

To deploy your changes after merging, see the documentation: PCYsg-mMA-p2

@noahtallen
noahtallen requested a review from a team August 10, 2021 02:40
@noahtallen noahtallen self-assigned this Aug 10, 2021
@noahtallen
noahtallen force-pushed the update/sass-with-deprecation-warn branch from 35e3fb7 to c8abdee Compare August 10, 2021 02:44
@noahtallen
noahtallen force-pushed the update/sass-with-deprecation-warn branch from 4597f7c to d8d71d1 Compare August 23, 2021 23:56
@noahtallen
noahtallen force-pushed the update/sass-with-deprecation-warn branch from d8d71d1 to 7961103 Compare August 24, 2021 00:05
@noahtallen

Copy link
Copy Markdown
Contributor Author

Currently getting a lot of [webpack.cache.PackFileCacheStrategy] Error: No serializer registered for SassError errors, which I'll try to figure out tomorrow. @scinos do you know anything about that error?

@scinos

scinos commented Aug 24, 2021 •

Copy link
Copy Markdown
Contributor

[webpack.cache.PackFileCacheStrategy] Error: No serializer registered for SassError is a warning that says that particular module won't be cached because sass-loader doesn't provide a serializer for SassError. It makes the log so noisy that it hides the actual error (#15 199.6 [output clipped, log limit 1MiB reached]).

When building this branch locally with PROFILE=true PERSISTENT_CACHE=true yarn build-client-evergreen I get a ton of error like this one:

ERROR in ./assets/stylesheets/gutenboarding.scss
Module build failed (from ../node_modules/mini-css-extract-plugin/dist/loader.js):
ModuleBuildError: Module build failed (from ../packages/calypso-build/node_modules/sass-loader/dist/cjs.js):
SassError: Undefined mixin.
   ╷
12 │ ┌     @include breakpoint-deprecated( '>960px' ) {
13 │ │         width: 100px;
14 │ │         height: 100px;
15 │ └     }
   ╵
  client/assets/stylesheets/shared/_loading.scss 12:2  @import
  client/assets/stylesheets/gutenboarding.scss 8:9     root stylesheet
    at processResult (/Users/sergio/src/automattic/wp-calypso/node_modules/webpack/lib/NormalModule.js:703:19)
    at /Users/sergio/src/automattic/wp-calypso/node_modules/webpack/lib/NormalModule.js:809:5
    at /Users/sergio/src/automattic/wp-calypso/node_modules/loader-runner/lib/LoaderRunner.js:399:11
    at /Users/sergio/src/automattic/wp-calypso/node_modules/loader-runner/lib/LoaderRunner.js:251:18
    at context.callback (/Users/sergio/src/automattic/wp-calypso/node_modules/loader-runner/lib/LoaderRunner.js:124:13)
    at /Users/sergio/src/automattic/wp-calypso/packages/calypso-build/node_modules/sass-loader/dist/index.js:54:7
    at Function.call$2 (/Users/sergio/src/automattic/wp-calypso/node_modules/sass/sass.dart.js:93911:16)
    at _render_closure1.call$2 (/Users/sergio/src/automattic/wp-calypso/node_modules/sass/sass.dart.js:82164:12)
    at _RootZone.runBinary$3$3 (/Users/sergio/src/automattic/wp-calypso/node_modules/sass/sass.dart.js:27587:18)
    at _FutureListener.handleError$1 (/Users/sergio/src/automattic/wp-calypso/node_modules/sass/sass.dart.js:26136:19)
 @ ./landing/gutenboarding/index.tsx 19:0-55

The as * defines the namespace for the import. Without it, you'd have to start referencing variables with the namespace prefixed.

The prelude in this branch doesn't include the as * part. When I added it, it fixed the above errors.

@matticbot

Copy link
Copy Markdown
Contributor

This PR does not affect the size of JS and CSS bundles shipped to the user's browser.

Generated by performance advisor bot at iscalypsofastyet.com.

@noahtallen

Copy link
Copy Markdown
Contributor Author

The prelude in this branch doesn't include the as * part. When I added it, it fixed the above errors.

Ahhh, I must have accidentally removed it when I rebased.

@noahtallen
noahtallen merged commit 43d8d1a into trunk Aug 24, 2021
@noahtallen
noahtallen deleted the update/sass-with-deprecation-warn branch August 24, 2021 19:58
@github-actions github-actions Bot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Aug 24, 2021
@noahtallen noahtallen changed the title (chore) Update Sass Library chore: Update Sass Library Sep 3, 2021
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.

3 participants