Skip to content

Commit

Permalink
Lodash: Refactor persistence plugin away from _.merge() (#47790)
Browse files Browse the repository at this point in the history
* Lodash: Refactor persistence plugin away from _.merge()

* Merge only plain objects
  • Loading branch information
tyxla authored Feb 7, 2023
1 parent bc6f111 commit 53fab10
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 32 deletions.
79 changes: 49 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/data/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"@wordpress/is-shallow-equal": "file:../is-shallow-equal",
"@wordpress/priority-queue": "file:../priority-queue",
"@wordpress/redux-routine": "file:../redux-routine",
"deepmerge": "^4.3.0",
"equivalent-key-map": "^0.2.2",
"is-plain-object": "^5.0.0",
"is-promise": "^4.0.0",
Expand Down
6 changes: 4 additions & 2 deletions packages/data/src/plugins/persistence/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* External dependencies
*/
import { isPlainObject } from 'is-plain-object';
import { merge } from 'lodash';
import deepmerge from 'deepmerge';

/**
* Internal dependencies
Expand Down Expand Up @@ -193,7 +193,9 @@ function persistencePlugin( registry, pluginOptions ) {
// subset of keys.
// - New keys in what would otherwise be used as initial
// state are deeply merged as base for persisted value.
initialState = merge( {}, initialState, persistedState );
initialState = deepmerge( initialState, persistedState, {
isMergeableObject: isPlainObject,
} );
} else {
// If there is a mismatch in object-likeness of default
// initial or persisted state, defer to persisted value.
Expand Down

1 comment on commit 53fab10

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 53fab10.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4117910913
📝 Reported issues:

Please sign in to comment.