-
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
Remove lodash dependency from WordPress packages. #17025
Comments
It would be good to have some usage analysis across the different packages. My assumption is that for some packages it would be easier to remove |
Good point and I think that will be useful in helping inform any decision. I'll take on tackling that first. |
Is the idea to import any lodash functions that will continue to be used (i.e. There's also |
I personally don't see a lot of value in removing lodash. Removing lodash basically means replacing its functions with custom built ones? What's the difference between a custom utility package and lodash aside "not invented here"?
I agree with @talldan that if we were to change something, we should consider loading and bundling specific lodash functions. But that said, in the WordPress context, it's not a perfect solution because we'll end up with duplicated functions across bundles which might not be better in terms of bundle size. I know I'm sounding "negative" here but do we really have a problem with lodash right now? |
Not necessarily. For many utilities there are native replacements. IMHO, if within a package all lodash-helpers can easily be replaced with native solutions (e.g. |
Yes, that makes sense @swissspidy and I'm all for native solutions and I'm all for explorations to reduce our reliance on lodash but there are a lot of cases where it may seem that lodash is useless but in fact, it is:
|
I agree, it is probably not a problem to load all of The main problems I do see with is forcing developers (and all website visitors) to load all of |
From the comments here, I agree that the original proposal of removing all dependency on lodash is not necessary. However as @adamsilverstein articulated (and in sync with the original prompt for this discussion), I think it's worthwhile to explore what packages having a dependency on lodash and potentially used on the frontend could have that dependency removed. However, this still leaves the question for what to do with the few functions that aren't trivial to replace (as noted for I still plan on doing a review of package use of lodash - but in light of the convo here I'll focus on the packages potentially used on the frontend. |
Previously: #9374 and #9374 (comment) |
I tested |
There is a related issue opened by @mdmag in #27982 that covers a very similar topic:
I'm also sharing my response left there:
|
I'm planning to start working incrementally on removing Lodash completely from the repository. Usage is not so high, and the bundle size impact will be huge for some of the packages when used externally. |
Nice idea taking this on @tyxla! I was wondering if it's worth having a linting rule or something that prevents the methods you've removed from being re-imported? (I'm just imagining the potential whack-a-mole in case other PRs attempt to reintroduce any of the function imports you've removed 😅) Apologies if this has been discussed already! |
A year later, after a few hundred PRs, we're finally there! #52561 removes the very last usage within a There are some de-duplications and optimizations we can work on, but they're not a requirement for closing this one and I'll be working on them afterwards. |
Right now lodash is used throughout various
@wordpress
packages in this repo because it's convenient and handles a lot of mundane things/logic that aren't worth duplicating. However there is a cost to using it:lodash.min.js
is 73.3kbFor this issue, I'd like to propose that we eliminate lodash usage across all our repository packages to reduce/remove the cost incurred by it. To do so:
_.kebabCase
or_.isPlainObject
might be good candidates for this package. Difficulty here would be how to name this package and clearly defining what goes in it (we don't want it becoming a "catch all" type of package.@wordpress/*
packages.Initially, I've started with
@wordpress/element
dependency here.I'm willing to spearhead this and get it completed, but before I begin, here's some decisions that we should make to move forward on this issue:
Is removing
lodash
dependency something we want to do? Everywhere or just select packges?Should we create a new package to contain specific lodash functions (like
_.kebabCase
) that can be used where needed instead of lodash? If yes, what name should we give the package. What conventions should we describe for what is allowed in the package?The text was updated successfully, but these errors were encountered: