Repository navigation
Lodash: Remove completely from site editor - #52480
Merged
Merged
Conversation
tyxla
requested review from
Mamaduka,
aristath,
brookewp,
chad1008,
fabiankaegy,
flootr,
jsnajdr,
ntsekouras,
ramonjd,
sgomes and
swissspidy
July 10, 2023 17:02
tyxla
commented
Jul 10, 2023
| return ( entities || [] ).map( ( entity ) => ( { | ||
| ...entity, | ||
| name: decodeEntities( get( entity, path ) ), | ||
| name: decodeEntities( getValueFromObjectPath( entity, path ) ), |
Member
Author
There was a problem hiding this comment.
path is expected to be a string, and for entity we're handling nullish values just in case.
| const value = presetAttributeValue | ||
| ? `var:preset|${ STYLE_PATH_TO_CSS_VAR_INFIX[ presetAttributeKey ] }|${ presetAttributeValue }` | ||
| : get( attributes.style, path ); | ||
| : getValueFromObjectPath( attributes.style, path ); |
Member
Author
There was a problem hiding this comment.
path is expected to be an array, and for attributes.style we're handling nullish values just in case:
| "downloadjs": "^1.4.7", | ||
| "fast-deep-equal": "^3.1.3", | ||
| "is-plain-object": "^5.0.0", | ||
| "lodash": "^4.17.21", |
Member
Author
There was a problem hiding this comment.
One of the last packages to remove the dependency from 🥳
|
Size Change: +49 B (0%) Total Size: 1.43 MB
ℹ️ View Unchanged
|
|
Flaky tests detected in 588b5cb. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5510853269
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
This PR removes Lodash's
_.get()from the@wordpress/edit-sitepackage and since those are the last Lodash usages there, it removes the Lodash dependency.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?
We're using direct access with optional chaining as an alternative. It might feel like we're being repetitive adding the same function twice, but it's not the same actually: in one of the cases it works with an array path, and in the other case, it works with a string path. There are other usages and different implementations of
getValueFromObjectPaththroughout the codebase and I'm planning to follow up with unifying them in another PR.Testing Instructions
_.set()inPushChangesToGlobalStylesControl#52404.