WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.53k stars 4.21k forks source link

Components: moving away from Emotion #66806

Open ciampo opened 2 weeks ago

ciampo commented 2 weeks ago

Related to #61232

Goal

Context

The @wordpress/components and the @wordpress/block-editor packages use the Emotion for authoring styles.

Emotion is a CSS-in-JS library that dynamically computes and applies styles at runtime, allowing a developer to change the styles based on JS variables / react props. It also allows for locally scoped files (obfuscating classnames), and colocation of styles and markup.

Unfortunately, Emotion also has a few drawbacks:

cc @WordPress/gutenberg-components

ciampo commented 2 weeks ago

Update:

Folks from @WordPress/gutenberg-components spent some time in the past couple of days testing a few approaches.

Long-term goal

As the long-term solution, we discussed replacing Emotion with CSS modules.

@mirka started experimenting with adding the necessary steps to the build:packages npm script, with initially encouraging results.

Goals:

One thing to consider, is whether we should use "SCSS" modules instead, so that all styles are authored in SCSS across the whole repository. Using SCSS will also allow to re-use SCSS variables, without the need for re-creating them in another language (as we currently do with JS variables for CSS-in-JS styles).

Intermediate step

We discussed applying an intermediate step, where we'd keep the CSS-in-JS code as "untouched" and possible, and we'd focus on swapping Emotion with another (no-runtime) CSS-in-JS. We looked at linaria, StyleX, and vanilla-extract.

For the above reasons, @ciampo 's initial conclusion is that it may be a better strategy to skip the intermediate step, and instead refactor the Emotion code directly to whatever long-term solution we want to adopt (eg. CSS modules).