Skip to content

Replace classnames with clsx#61138

Merged
DaniGuardiola merged 21 commits into
trunkfrom
ignore/clsx-size-test
May 3, 2024
Merged

Replace classnames with clsx#61138
DaniGuardiola merged 21 commits into
trunkfrom
ignore/clsx-size-test

Conversation

@DaniGuardiola

@DaniGuardiola DaniGuardiola commented Apr 26, 2024

Copy link
Copy Markdown
Member

PR originally started as a test, see: #61091 (comment)

Then it replaced #61091, see: #61091 (comment)

There are no significant changes in this PR that weren't already part of the previous PR, I only synced with trunk and ensured that all usage of classnames was still consistently replaced with cslx.

@DaniGuardiola DaniGuardiola disabled auto-merge May 1, 2024 13:13
Comment thread packages/block-editor/CHANGELOG.md
Comment thread .github/setup-node/action.yml Outdated
Comment thread .github/setup-node/action.yml
@desrosj

desrosj commented May 1, 2024

Copy link
Copy Markdown
Member

It looks like this PR is the first one making a change to the package.json file since #61211, which means it's the first one running the npm ci step.

I tried rolling that back the update to actions/setup-node, and and it worked for me (#61289). I also moved the debugging steps we added above to that PR to keep this one specific to the task at hand.

@DaniGuardiola

DaniGuardiola commented May 3, 2024

Copy link
Copy Markdown
Member Author

Thanks @desrosj, I'm gonna remove the unrelated CI debug changes in order to merge the PR.

@DaniGuardiola DaniGuardiola changed the title Try: Replace classnames with clsx Replace classnames with clsx May 3, 2024
@DaniGuardiola DaniGuardiola added Needs Dev Note Requires a developer note for a major WordPress release cycle and removed Needs Dev Note Requires a developer note for a major WordPress release cycle labels May 3, 2024
@DaniGuardiola DaniGuardiola merged commit c566725 into trunk May 3, 2024
@DaniGuardiola DaniGuardiola deleted the ignore/clsx-size-test branch May 3, 2024 20:04
@github-actions github-actions Bot added this to the Gutenberg 18.4 milestone May 3, 2024
@tbradsha

tbradsha commented Jun 5, 2024

Copy link
Copy Markdown

Noting that this replaced at least five instances of classnames/dedupe with clsx, so may have some unintended consequences.

@DaniGuardiola

Copy link
Copy Markdown
Member Author

@tbradsha thanks for the heads up, but this was accounted for so nothing to worry about, see previous PR as mentioned in the description here: #61091

@tbradsha

tbradsha commented Jun 5, 2024

Copy link
Copy Markdown

this was accounted for so nothing to worry about

At least this change introduces an unintentional side effect:

diff --git a/packages/block-library/src/cover/edit.native.js b/packages/block-library/src/cover/edit.native.js
index 1fc1519f47f94..c5fe140e8fe23 100644
--- a/packages/block-library/src/cover/edit.native.js
+++ b/packages/block-library/src/cover/edit.native.js
@@ -10,7 +10,7 @@ import {
 	Platform,
 } from 'react-native';
 import Video from 'react-native-video';
-import classnames from 'classnames/dedupe';
+import clsx from 'clsx';
 
 /**
  * WordPress dependencies
@@ -298,7 +298,7 @@ const Cover = ( {
 
 		// Ensure that "is-light" is removed from "className" attribute if cover background is dark.
 		if ( isCoverDark && attributes.className?.includes( 'is-light' ) ) {
-			const className = classnames( attributes.className, {
+			const className = clsx( attributes.className, {
 				'is-light': false,
 			} );
 			setAttributes( {

Assuming attributes.className is set to "some-class is-light":

classes = 'some-class is-light';
dedupe(classes,{'is-light': false}; // 'some-class'
classnames(classes,{'is-light': false}) // 'some-class is-light'
clsx(classes,{'is-light': false}) // 'some-class is-light'
  • classnames.dedupe() would remove is-light
  • clsx (and the standard classnames) would not remove is-light. In this case, the second argument does nothing, since it's always set to false.

@DaniGuardiola

Copy link
Copy Markdown
Member Author

Good catch, thanks. Will fix.

manzoorwanijk added a commit that referenced this pull request Jun 9, 2026
Gutenberg standardised on `clsx` in 2024 ([#61138]) and removed every
`classnames` declaration across the monorepo. There is currently no
guardrail preventing it from being re-added later — an `npm install
classnames` in any workspace would land silently.

Add a `Banned` version group to `syncpack.config.mjs` that fails
`lint:deps` (and CI) on any declaration of `classnames` in any
package.json. The rule is preventive: no current declarations are
affected.

Picked up as the follow-up suggested in #77950's review.

[#61138]: #61138

Co-authored-by: manzoorwanijk <manzoorwanijk@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
peterwilsoncc pushed a commit to peterwilsoncc/gutenberg-build that referenced this pull request Jun 10, 2026
Gutenberg standardised on `clsx` in 2024 ([#61138]) and removed every
`classnames` declaration across the monorepo. There is currently no
guardrail preventing it from being re-added later — an `npm install
classnames` in any workspace would land silently.

Add a `Banned` version group to `syncpack.config.mjs` that fails
`lint:deps` (and CI) on any declaration of `classnames` in any
package.json. The rule is preventive: no current declarations are
affected.

Picked up as the follow-up suggested in #77950's review.

[#61138]: WordPress/gutenberg#61138

Co-authored-by: manzoorwanijk <manzoorwanijk@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>

Source: WordPress/gutenberg@d651a81
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Code Quality Issues or PRs that relate to code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants