Remove legacy `getModulesData` JS function and `_googlesitekitLegacyData.modules` global
See original GitHub issueRelated to #3647: All usages of the legacy function getModulesData
which relies on the _googlesitekitLegacyData.modules
global should be refactored, and then those two pieces should be entirely removed.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- All JS components currently relying on
getModulesData
should be refactored to use thegetModules
orgetModule
datastore selector instead, using React hooks. - The
getModulesData
function should be entirely removed. - The
_googlesitekitLegacyData.modules
global should be entirely removed, including where it is set in PHP.
Implementation Brief
Update getModules
code when changing from getModulesData
- In any place where we change from
getModulesData
togetModules
, note that the data returned fromgetModules
is slightly different. Most of the keys/values/info is the same, but here’s a map of the old to new keys:sort
(old) =>order
(new)screenID
(old) => N/A (not needed)autoActivate
(old) =>forceActive
(new)required
(old) =>dependencies
(new)settings
(old) => N/A (if any data fromsettings
is needed by components usinggetModulesData
it will need refactoring)- All other keys are the same or are only available in the new API
SettingsModules
component
- Remove the
useEffect
in https://github.com/google/site-kit-wp/blob/3db19cbeca41145aefc6c6c3383ee9b66e8b4121/assets/js/components/settings/SettingsModules.js#L38 and changemodulesData
toconst moduleData = useSelect( ( select ) => select( CORE_MODULES ).getModules() );
(renaming themodulesData
tomodules
as well).
Some component require changing to functional components to use hooks, but this is straightforward:
- Convert
assets/js/components/legacy-notifications/dashboard-setup-alerts.js
to a functional component. Refactor https://github.com/google/site-kit-wp/blob/3db19cbeca41145aefc6c6c3383ee9b66e8b4121/assets/js/components/legacy-notifications/dashboard-setup-alerts.js#L62-L67 to access the module in a hook before theswitch
statement. - Change https://github.com/google/site-kit-wp/blob/3db19cbeca41145aefc6c6c3383ee9b66e8b4121/assets/js/components/legacy-notifications/dashboard-modules-alerts.js#L38 to a functional component, moving the
componentDidMount
logic to auseMount
hook. Then, use thegetModules()
selector to replace the current usage ofgetModulesData()
.
Other changes that don’t require converting to functional components but require refactoring:
- Change https://github.com/google/site-kit-wp/blob/3db19cbeca41145aefc6c6c3383ee9b66e8b4121/assets/js/components/notifications/UnsatisfiedScopesAlert.js#L61 to select all modules using the
getModules()
selector and passmodules
as an argument tomapScopesToModuleNames
in the same file.
Misc changes
- ~Remove
assets/js/modules/optimize/index.legacy.js
.~ (This is still required, actually, so should not be removed.) - Remove
assets/js/components/legacy-notifications/data-error.js
. - Remove
assets/js/util/index.test.js
. - Remove the https://github.com/google/site-kit-wp/blob/3db19cbeca41145aefc6c6c3383ee9b66e8b4121/assets/js/util/index.js#L118 function.
PHP Changes
- Remove
'modules'
, and'permissions'
keys from the array inget_inline_data
inAssets.php
(see: https://github.com/google/site-kit-wp/blob/3db19cbeca41145aefc6c6c3383ee9b66e8b4121/includes/Core/Assets/Assets.php#L811-L827) - Remove the filter
googlesitekit_modules_data
fromincludes/Core/Modules/Modules.php
: https://github.com/google/site-kit-wp/blob/3db19cbeca41145aefc6c6c3383ee9b66e8b4121/includes/Core/Modules/Modules.php#L163-L187 - <del>Remove this function (
prepare_info_for_js
) fromincludes/Core/Modules/Module.php
: https://github.com/google/site-kit-wp/blob/47b723d1416fa48b4e9df73b2970e868e1ccece8/includes/Core/Modules/Module.php#L176 as it’s no longer used </del> (Note: this is still used but in a different way so should remain.)
Test Coverage
- Aside from the tests removed, mentioned above, no test changes should occur. Existing tests should pass.
Visual Regression Changes
- No changes should occur.
QA Brief
- Notifications and Settings pages, mainly, should continue to function as before. This change removes global code set by PHP, so check the developer/browser console during browsing and ensure no errors/warnings related to the
_googlesitekitLegacyData.modules
variable are displayed.
Changelog entry
- N/A
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:8 (2 by maintainers)
Top Results From Across the Web
How to remove all Global Modules in Node.js ? - GeeksforGeeks
For Window users: The Windows user can remove all the Node.js modules globally by just deleting the content of the following directory:
Read more >[#MDL-57490] Remove old legacy global js functions
We've got a number of functions in javascript-static (e.g. checkall) which have been in the global namespace for nearly 14 years and are...
Read more >How to migrate legacy JS app to modules - Stack Overflow
As you move a function from legacy.js to myNiceModule.js , check to see if it still has clients that are aware of it...
Read more >DevTools architecture refresh: migrating to JavaScript modules
How we migrate Chrome DevTools to JavaScript modules. ... goal would be to remove all "legacy export objects", cleaning up the global scope....
Read more >Deprecated and obsolete features - JavaScript - MDN Web Docs
These features are likely stable because removing them will cause backward compatibility issues and break legacy websites. (JavaScript has ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@tofumatt the
getDataErrorComponent
function also relies ongetModulesData
function but it looks like we don’t use it anymore and can delete it. Could you please update IB to delete the file with thegetDataErrorComponent
function entirely? Plus, could you, please, clarify what exactly needs to be deleted from the Assets.php file?A bit of the functional conversions/refactoring here might be a bit tricky for anyone less familiar with these files, so marking this as an 11… but it’s a high estimate and covers potentially the broad QA requirements of this issue as well.