google / google/site-kit-wp

Replace usage of Lodash `cloneDeep` with native `structuredClone`.

Open
#6,492 11 comments 3 reactions 0 assignees View on GitHub
blocked upstream Good First Issue Next Up P2 Type: Enhancement
Dominant language
JavaScript
Stars
1.4k
Forks
383
Avg merge
4d 14h
Merged PRs (30d)
77

Description

## Feature Description

As discussed in [this article](https://www.builder.io/blog/structured-clone), the native [`structuredClone`](https://developer.mozilla.org/en-US/docs/Web/API/structuredClone) function can be used instead of `cloneDeep`. It has good browser support and would allow us to marginally reduce the bundle size.

---------------

_Do not alter or remove anything below. The following sections will be managed by moderators only._

## Acceptance criteria

* Use of `cloneDeep` within the codebase should be replaced with `structuredClone`.

## Implementation Brief

* Wait until we upgrade our version of Node to at least `17` (probably `18`), see #6026.
* Replace every import of `cloneDeep` with `structuredClone`, eg `cloneDeep( object )` to `structuredClone( object )`.
* At the time of writing, we have usage in the following files:
* `assets/js/modules/analytics-4/datastore/properties.test.js`
* `assets/js/modules/analytics-4/components/module/ModulePopularPagesWidgetGA4/index.js`
* `assets/js/modules/analytics-4/components/dashboard/DashboardAllTrafficWidgetGA4/UserCountGraph.js`
* `assets/js/modules/analytics-4/components/dashboard/DashboardAllTrafficWidgetGA4/UserDimensionsPieChart.js`
* `assets/js/modules/analytics-4/utils/data-mock.js`
* `assets/js/modules/reader-revenue-manager/components/settings/SettingsEdit.stories.js`
* `assets/js/modules/reader-revenue-manager/datastore/publications.test.js`
* `assets/js/components/GoogleChart/utils.js`
* `assets/js/components/wp-dashboard/WPDashboardPopularPagesGA4.js`
* `storybook/utils/resetGlobals.js`

### Test Coverage

* Tests should continue to pass without change; no new tests are needed.

## QA Brief

*

## Changelog entry

*

Contributor guide

Open the contributing guide

Research direction

First check the Node upgrade status in #6026, then search the listed JavaScript files for Lodash cloneDeep imports and usages. Replace each listed usage with structuredClone and run the existing test suite; done means no cloneDeep usage remains and tests continue to pass without new tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.