Open ciampo opened 2 weeks ago
Update:
Folks from @WordPress/gutenberg-components spent some time in the past couple of days testing a few approaches.
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:
styled
components with the underlying un-styled component and move styles to classnameStyleProvider
component and its usages across the codebase, useCx
hook, rtl
utility@emotion/*
dependencies (storybook, tests setup, etc)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).
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).
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