Remove legacy error notifications infrastructure in favor of store-based one
See original GitHub issueThe storeErrorNotifications feature flag should be removed and the logic behind it should become the new default, more specifically the only version available.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
Part 1: Replace generic errors legacy infrastructure
- The principal usage of
showErrorNotificationshould be replaced with a datastore-driven alternative, using thecore/sitestore:- It should receive actions
setInternalServerError( error )andclearInternalServerError()and a selectorgetInternalServerError(), all of which behave similarly to their*AuthErrorcounterparts in thecore/userstore. - The usages of
showErrorNotificationthat handle errors after a failed module activation (which is basically almost all usages of that function in total) should usesetInternalServerErrorinstead (also see next bullet point for context on how to replace the notifications themselves). - A new
InternalServerErrorcomponent should be implemented inassets/js/components/notifications/which should display the error notification forgetInternalServerError(inspired by logic in theAuthErrorcomponent), with similar appearance (e.g. title, format etc.) that the notifications from the current usages ofshowErrorNotificationhave. That component should then be included in theErrorNotificationscomponent, on top of the two other components.
- It should receive actions
- The
showErrorNotificationfunction and its remaining usages should be completely removed.- The now unused
GenericErrorcomponent should also be removed.
- The now unused
Part 2: Remove legacy error notifications infrastructure
- The
storeErrorNotificationsfeature flag should be removed and what’s currently behind it should become the new way to display error notifications. - The legacy
ErrorNotificationcomponent (sometimes referred to asLegacyErrorNotifications) should no longer be used. - The
googlesitekit.ErrorNotificationfilter and all of its usages should be removed, e.g.:- the legacy
ErrorNotification - the relevant logic in the legacy
handleWPErrorfunction and inassets/js/components/legacy-notifications/index.js
- the legacy
Implementation Brief
Numbering here matches numbering on AC. Refer to AC first
Part 1
1 .i. Create a new datastore assets/js/googlesitekit/data/site/errors.js. Copy relevant actions and selectors from assets/js/googlesitekit/datastore/user/authentication.js but change names and constants (and ignore all the code for storing authentication state. This datastore is much larger)
1 .ii. Follow AC. Some existing calls to showErrorNotification have a second argument e.g.
showErrorNotification( GenericError, {
id: 'activate-module-error',
title: __( 'Internal Server Error', 'google-site-kit' ),
description: error.message,
format: 'small',
type: 'win-error',
} );
and another call passes in an instantiated Notification component showErrorNotification( InvalidCredentialsWarning );
The id, title, description, learnMoreURL, and learnMoreLabel change
So copying AuthError we’d want these passed in error.data
-
iii. Follow IB. Copy like
AuthErrorbut pass in the keys above to the inner `Notification component. -
i. Follow AC
“The usages of showErrorNotification that handle errors after a failed module activation (which is basically almost all usages of that function in total)”
The only other usage of showErrorNotification in assets/js/components/legacy-notifications/data-error.js is to be deleted
Part 2
-
Remove
storeErrorNotificationsfromfeature-flags.json -
Remove any usage of this
storeErrorNotificationsflag from codebase. Not many uses. InHeader.jsmake the component behind the flag always visible. Tests should still pass where previously this was set. -
Remove <LegacyErrorNotification/> from
Header.js(double-check no more instances) -
Do as per AC
Test Coverage
- Create a
assets/js/googlesitekit/data/site/errors.test.js, copying relevant tests fromassets/js/googlesitekit/data/site/authentication.test.js - Currently
assets/js/util/test/showErrorNotification.jscontains tests forshowErrorNotification. Check thatsetInternalServerError,clearInternalServerErrorandgetInternalServerErrorcause corresponding changes inInternalServerError(displayed, not displayed, displays correct message)
Visual Regression Changes
- Changes not expected
QA Brief
- Check the new
datastore/site/errorsstore has been created with the following:- action:
setInternalServerError - action:
clearInternalServerError - selector:
getInternalServerError
- action:
- Check that all instances of
showErrorNotificationhave been replaced with dispatches tosetInternalServerError - Check the
storeErrorNotificationsflag has been removed fromfeature-flags.jsonand from everywhere in the codebase - Check the
LegacyErrorNotificationcomponent has been removed fromHeader.jsand everywhere else in the codebase - Check that js tests pass
Changelog entry
- N/A
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (13 by maintainers)

Top Related StackOverflow Question
@eugene-manuilov @aaemnnosttv Please do not merge this until
developis open towards the 1.38.0 release, since we want to time this to go out together with #1997, #2077, and #2258.@Hazlitte that’s definitely a typo on my behalf 😄 Apologies. Put any more questions in here!