Conversation
|
Size Change: +218 B (0%) Total Size: 1.24 MB
ℹ️ View Unchanged
|
|
This is a big merge. Do we know what is really saved by this change in terms of bundle size? It'd be a good rationale for the refactoring. |
e486772 to
2e1873b
Compare
Thank you for asking. I know it looks like a lot in this PR, but even if the change touches a lot of files, it's a very straightforward and non-risky one, which is why I preferred to do it in a single PR. It's fair to say particular PR doesn't achieve much in terms of bundle size improvement immediately. However, the bundle size of each package that directly or consequently uses Lodash will end up reduced once all of Lodash is removed. Currently, Lodash is still used in most of the packages, and it's around 73KB in size. We're currently in the process of removing all these usages incrementally (see Removing Lodash) and the collective result is yet to be seen when we end up having fewer and fewer usages in the packages. This comment explains a lot of why we're heading in that direction: #16938 (comment) |
|
Cool thanks for explaining @tyxla 🙇🏻 |
|
Isn't lodash removed by using the WordPress Dependency Extraction Plugin? So technically it does not increase the bundle size right? |
That is valid only for the wp-admin, though. Outside of wp-admin, or when a package is used externally, |
What?
Lodash's
noopis the most used Lodash method in this repository. It's also one of the simplest: it's just an empty function that takes no arguments and returns nothing. This PR aims to remove that usage. While it might look like a large one, it really does the same thing for allnoopoccurrences.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-fetchpackage haslodashas a dependency #39495How?
Removing
noopis straightforward in favor of a simple function with no arguments and an empty body that returns nothing. I've made a conscious decision here not to abstract our own function and reuse it everywhere because that would needlessly complicate the dependency graph. Instead, I've declared anoopfunction inline per component where necessary, and that way we get the best of both worlds: we have no additional dependencies, but still, we prevent extra re-renders becausenoopwill always be the same within each component.Testing Instructions
Verify all tests still pass.
Notes
Seems like there is a JS unit test failure, but it's unrelated, and seems to be caused by an obsolete version of#41675 has been merged, so unit tests will now pass.caniuse-lite, I'm proposing a fix for it in #41675.