-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lodash: Refactor away from _.kebabCase()
in generic template modal
#51910
Conversation
@@ -1,7 +1,7 @@ | |||
/** | |||
* External dependencies | |||
*/ | |||
import { kebabCase } from 'lodash'; | |||
import { paramCase as kebabCase } from 'change-case'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, we could ditch the kebabCase()
completely since passing a non-slugified title as a slug
to the wp_insert_post()
function will slugify it anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually suggested that approach for a similar kebabCase
use case in #51911.
Size Change: -7 B (0%) Total Size: 1.44 MB
ℹ️ View Unchanged
|
ce466ad
to
c937360
Compare
This is the last |
Flaky tests detected in c937360. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5398908281
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🚀 🚢
…ordPress#51910) * Lodash: Refactor away from _.kebabCase() in generic template modal * Deprecate _.kebabCase()
What?
This PR removes Lodash's
_.kebabCase()
from the generic template creation modal component.Since this is the last usage of
_.kebabCase()
, we're also deprecating the function through ESLint.Why?
Lodash is known to unnecessarily inflate the bundle size of packages, and in most cases, it can be replaced with native language functionality. See these for more information and rationale:
@wordpress/api-fetch
package haslodash
as a dependency #39495How?
We're replacing the usage with
paramCase
from thechange-case
package, which we've already been utilizing for the general use cases. I think that's fine since a unique slug is being generated on the backend and used instead of the one generated on the client anyway:gutenberg/packages/edit-site/src/components/add-new-template/new-template.js
Lines 191 to 207 in 1464f18
plus, slugs with Unicode characters tend to be less readable anyway, so I personally see this as an improvement. For example, using
初島しじ下法ウ共旅もレあし重名どて暮園
as the title would result in the template slug beingwp-custom-template-%25e5%2588%259d%25e5%25b3%25b6%25e3%2581%2597%25e3%2581%2598%25e4%25b8%258b%25e6%25b3%2595%25e3%2582%25a6%25e5%2585%25b1%25e6%2597%2585%25e3%2582%2582%25e3%2583%25ac%25e3%2581%2582%25e3%2581%2597%25e9%2587%258d%25e5%2590%258d%25e3%2581%25a9%25e3%2581%25a6%25e6%259a%25ae%25e5%259c%2592
, which is quite terrible IMHO.Testing Instructions
/wp-admin/site-editor.php?path=%2Fwp_template