-
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/element' #16938
Comments
So, the following lodash functions are relatively trivial to re-implement using native js (for the use-case in
However, there are a couple that are a bit more involved:
Since the last two would involve essentially copying in the same thing that lodash did I'm wondering if the effort here is still worth it. One alternative I've been pondering when it comes to how WordPress exposes libraries now that javascript is more "first-class" is why we don't take advantage of cdn distributed scripts which to some degree can eliminate the concerns of common dependencies such as |
One other advantage would be avoiding conflicts with other code on the page using lodash or underscore.
These are pretty tiny, can we just import and bundle them (or copy the code directly)? https://github.com/lodash/lodash/blob/master/kebabCase.js |
They are tiny, but they have dependencies (follow the internal dependency chain for kebabCase for instance). I'm wondering though, if there are only a few lodash helpers like these two, if we should just use the custom builds feature of lodash and create a special WP package ( |
worth a try, removing the lodash dependency feels pretty valuable, especially in the WordPress admin context. |
Is |
It's extensively used in multiple packages in this repository. Ideally it'd be nice to remove it as a dependency everywhere and instead just expose a subset of lodash utils for use (via another package). I'll create another issue for discussing this. |
One small concern is that as a third party developer, I've used lodash extensively within my own blocks, using the build provided in core. I can understand the appeal of removing a dependency but it feels like a small price to pay for all of the DevEx improvements it brings. Of course I can provide my own bundle if Gutenberg stops using it (or builds a custom build) but then we've just introduced a bunch of duplication as any plugin using lodash may decide to provide its own bundle. |
(In other words, this feels a bit like seeing the forest for the trees. It's a nice optimization, but what challenges/duplication would it lead to for third-parties?) |
I think for back compat we'd need to keep lodash available as an externally provided script in WP core. So your concern here Chris can be mitigated. As a flipside to your argument, there is also the challenge of current WordPress packages that have a dependency on lodash unnecessarily which adds additional weight everywhere they are enqueued. This specific pull is an example of that. If someone wants to use Not only that, but I have also experienced issues with third party compatibility on some sites where a plugin or theme a site owner has installed is using lodash on the frontend in one of their bundled scripts directly (not enqueuing what WP provides) which leads to conflicts. It'd be nice to avoid that problem if possible. |
Noting that @ZebulanStanphill has been doing some work lately to convert some usages of Lodash to native equivalents:
And a relevant comment of mine at #21054 (comment), notably this point:
We won't see any immediate benefit in the editor/admin of removing Lodash in individual packages, since the full module is referenced as an external to each package. It would only be at the point if and when the usage of Lodash is so little that inlining Lodash usage to respective packages would be of greater overall benefit. I'm not sure we'd ever get to that point, to be honest. It's true there's plenty of low-hanging fruit with the That said, I am sympathetic to a few specific reasons for reducing overall usage:
|
Is your feature request related to a problem? Please describe.
One of the challenges for projects that want to use various WordPress packages on the frontend is keeping js bundles small. While lodash itself is small in size, the fact that
wp.element
depends on it means that any code wanting to enqueue wp.element on the frontend is also going to load lodash.Since there are many native implementations for lodash features that can be used reliably (and in some cases are faster than lodash), I think it'd be good to remove this package's dependency on lodash and replace with native implementation.
Describe the solution you'd like
Replace lodash dependency in
@wordpress/element
by reimplementing any lodash features as native js.The text was updated successfully, but these errors were encountered: