Skip to content

Components: add Emotion migration guardrails#79442

Merged
ciampo merged 7 commits into
trunkfrom
codex/components-emotion-guardrails
Jun 24, 2026
Merged

Components: add Emotion migration guardrails#79442
ciampo merged 7 commits into
trunkfrom
codex/components-emotion-guardrails

Conversation

@ciampo

@ciampo ciampo commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

What?

Part of #66806.

Adds the first set of docs and lint guardrails for migrating @wordpress/components away from Emotion.

Why?

New component styles should use the existing SCSS Modules pattern while the current Emotion usage is migrated incrementally. This prevents the migration backlog from growing.

How?

  • Updates packages/components/CONTRIBUTING.md to recommend SCSS Modules and clsx for new component-local styles.
  • Documents CSS custom properties for dynamic values and conditional CSS Module classes for variants/state.
  • Replaces the Emotion-based deprecation styling example with a SCSS Modules example.
  • Adds a packages/components/src import guard that blocks new @emotion/* imports while temporarily allowlisting current Emotion files.

Testing Instructions

  1. Run npm run lint:md:docs -- packages/components/CONTRIBUTING.md.
  2. Run npm run lint:js -- tools/eslint/config.mjs.
  3. Run npm run lint:js -- packages/components/src --pass-on-unpruned-suppressions.
  4. Optionally add a new @emotion/react import to a non-allowlisted file under packages/components/src and confirm linting reports it.

Testing Instructions for Keyboard

Not applicable; this PR only changes documentation and lint rules.

Screenshots or screencast

Not applicable.

Use of AI Tools

Drafted with assistance from ChatGPT/Codex. The changes were reviewed before opening this PR.

@github-actions github-actions Bot added the [Package] Components /packages/components label Jun 23, 2026
@github-actions

Copy link
Copy Markdown

Size Change: 0 B

Total Size: 7.51 MB

compressed-size-action

@ciampo ciampo requested a review from Copilot June 23, 2026 15:40
@ciampo ciampo self-assigned this Jun 23, 2026
@ciampo ciampo added the [Type] Code Quality Issues or PRs that relate to code quality label Jun 23, 2026

This comment was marked as resolved.

Comment thread tools/eslint/config.mjs
! [ '@ariakit/react', 'framer-motion' ].includes(
name
)
) && ! name.startsWith( '@emotion/' )

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is to prevent emotion imports from being flagged twice

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also considered just restricting all @emotion imports everywhere, but… yeah I guess this is fine as a short term thing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we could start with the components package, and then apply the refactor to the whole repo after

@ciampo ciampo marked this pull request as ready for review June 23, 2026 16:18
@ciampo ciampo requested review from a team, ajitbohra and manzoorwanijk as code owners June 23, 2026 16:18
@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: ciampo <mciampini@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Comment thread packages/components/CONTRIBUTING.md Outdated
Comment thread packages/components/CONTRIBUTING.md
Comment thread tools/eslint/config.mjs
! [ '@ariakit/react', 'framer-motion' ].includes(
name
)
) && ! name.startsWith( '@emotion/' )

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also considered just restricting all @emotion imports everywhere, but… yeah I guess this is fine as a short term thing.

@ciampo ciampo force-pushed the codex/components-emotion-guardrails branch from 5b01375 to 4bb58ff Compare June 24, 2026 07:56
@ciampo ciampo marked this pull request as draft June 24, 2026 07:56
@ciampo ciampo marked this pull request as ready for review June 24, 2026 08:00
@ciampo ciampo enabled auto-merge (squash) June 24, 2026 08:03
@ciampo ciampo merged commit ee437d3 into trunk Jun 24, 2026
48 of 49 checks passed
@ciampo ciampo deleted the codex/components-emotion-guardrails branch June 24, 2026 08:31
@github-actions github-actions Bot added this to the Gutenberg 23.5 milestone Jun 24, 2026
! __nextHasNoOuterMargins &&
styles.deprecatedOuterMargins,
className
) }

@jsnajdr jsnajdr Jun 24, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this is a suboptimal usage of clsx, it should be:

clsx( 'components-my-component', styles.root, className, {
  [ styles.deprecatedOuterMargins ]: ! __nextHasNoOuterMargins,
} );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've noticed that this object key style can emit a literal undefined class in Jest tests. (Perhaps not super important, but a notable difference between the two styles.)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That can happen when styles.deprecatedOuterMargins is undefined. The value used as a key. And yes, the non-object form avoids that, because the result of the && expression is undefined and therefore ignored.

@ciampo ciampo Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, adding a small tweak in #79490

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Components /packages/components [Type] Code Quality Issues or PRs that relate to code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants