diff --git a/projects/plugins/protect/src/js/routes/scan/index.jsx b/projects/plugins/protect/src/js/routes/scan/index.jsx index ba105418a8cc0..1de1cb5448eb4 100644 --- a/projects/plugins/protect/src/js/routes/scan/index.jsx +++ b/projects/plugins/protect/src/js/routes/scan/index.jsx @@ -199,16 +199,12 @@ const ScanPage = () => { return ; } - if ( statusIsFetching ) { - return ; - } - if ( scanError ) { return ; } return ; - }, [ scanInProgress, status.currentProgress, statusIsFetching, scanError ] ); + }, [ scanInProgress, status.currentProgress, scanError ] ); return ( diff --git a/projects/plugins/protect/src/js/state/selectors.js b/projects/plugins/protect/src/js/state/selectors.js index 4ce9ad29f0bd2..4878643e42cdb 100644 --- a/projects/plugins/protect/src/js/state/selectors.js +++ b/projects/plugins/protect/src/js/state/selectors.js @@ -8,7 +8,7 @@ import { SCAN_IN_PROGRESS_STATUSES, SCAN_STATUS_OPTIMISTICALLY_SCANNING } from ' * @returns {boolean} Whether a scan is in progress. */ const scanInProgress = state => { - const { status, lastChecked } = selectors.getStatus( state ); + const { status, lastChecked, error } = selectors.getStatus( state ); const unavailable = selectors.getScanIsUnavailable( state ); // When "optimistically" scanning, ignore any other status or error. @@ -21,8 +21,13 @@ const scanInProgress = state => { return false; } - // If the status is one of the scanning statuses, or if we have never checked, we are scanning. - if ( SCAN_IN_PROGRESS_STATUSES.includes( status ) || ! lastChecked ) { + // If the status is one of the scanning statuses, we are scanning. + if ( SCAN_IN_PROGRESS_STATUSES.includes( status ) ) { + return true; + } + + // If we have no record of a previous scan, we must be queueing up the initial scan. + if ( ! lastChecked && ! error ) { return true; } @@ -43,6 +48,7 @@ const scanInProgress = state => { const scanError = state => { const { status, error, errorCode, errorMessage } = selectors.getStatus( state ); const unavailable = selectors.getScanIsUnavailable( state ); + const isFetching = selectors.getStatusIsFetching( state ); // If the scan results include an error, return it. if ( error ) { @@ -50,7 +56,15 @@ const scanError = state => { } // If the scan is unavailable, return an error. - if ( unavailable || ! status ) { + if ( unavailable ) { + return { + code: 'scan_unavailable', + message: __( 'We are having problems scanning your site.', 'jetpack-protect' ), + }; + } + + // If there is no status and we are not requesting it, return an error. + if ( ! status && ! isFetching ) { return { code: 'scan_unavailable', message: __( 'We are having problems scanning your site.', 'jetpack-protect' ),