google / site-kit-wp

Site Kit is a one-stop solution for WordPress users to use everything Google has to offer to make them successful on the web.
https://sitekit.withgoogle.com
Apache License 2.0
1.25k stars 290 forks source link

Migrate existing usage of lodash throttle in components to useThrottle hook #7123

Open tofumatt opened 1 year ago

tofumatt commented 1 year ago

Feature Description

We have several places in our React components where we import and use lodash's throttle directly, but because of React's component lifecycle, a new throttle function would be created on every component render, meaning it won't actually throttle if a re-render is triggered.

@nfmohit noticed this when working on #7045. He even helpfully created a useThrottle hook, but then it turns out we didn't need it for that particular PR (see: https://github.com/google/site-kit-wp/pull/7122#discussion_r1213757173).

But we should add that useThrottle hook back (see: e7557b6f52774c458cfdd87a92256c020f70fcbc for its commit) and migrate existing throttle calls to use a safer, re-render-persistent throttle function created from a React hook.


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

Acceptance criteria

Implementation Brief

Test Coverage

QA Brief

Changelog entry

ivonac4 commented 9 months ago

@tofumatt Are you still planning to work on this soon? If not, could you please unassign yourself so someone else can pick it up? Thank you!