Skip to content

Commit

Permalink
Add ampFirst prop to SiteScanContextProvider and set as false on sett…
Browse files Browse the repository at this point in the history
…ings screen
  • Loading branch information
westonruter committed Oct 11, 2021
1 parent 37c3026 commit 9b3f951
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
24 changes: 15 additions & 9 deletions assets/src/components/site-scan-context-provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,15 @@ const initialState = {
* @param {string} props.scannableUrlsRestPath The REST path for interacting with the scannable URL resources.
* @param {string} props.validateNonce The AMP validate nonce.
* @param {string} props.validateQueryVar The AMP validate query variable name.
* @param {boolean} props.ampFirst Whether scanning should be done with Standard mode being forced.
*/
export function SiteScanContextProvider( {
children,
fetchCachedValidationErrors = false,
scannableUrlsRestPath,
validateNonce,
validateQueryVar,
ampFirst = false,
} ) {
const { setAsyncError } = useAsyncError();
const [ state, dispatch ] = useReducer( siteScanReducer, initialState );
Expand Down Expand Up @@ -244,15 +246,18 @@ export function SiteScanContextProvider( {

try {
const { url } = scannableUrls[ currentlyScannedUrlIndex ];
const args = {
[ validateQueryVar ]: {
nonce: validateNonce,
omit_stylesheets: true,
cache,
},
};
if ( ampFirst ) {
args[ 'amp-first' ] = true;
}
const validationResults = await apiFetch( {
url: addQueryArgs( url, {
'amp-first': true,
[ validateQueryVar ]: {
nonce: validateNonce,
omit_stylesheets: true,
cache,
},
} ),
url: addQueryArgs( url, args ),
} );

if ( true === hasUnmounted.current ) {
Expand All @@ -276,7 +281,7 @@ export function SiteScanContextProvider( {
setAsyncError( e );
}
} )();
}, [ cache, currentlyScannedUrlIndex, scannableUrls, setAsyncError, status, validateNonce, validateQueryVar ] );
}, [ cache, currentlyScannedUrlIndex, scannableUrls, setAsyncError, status, validateNonce, validateQueryVar, ampFirst ] );

return (
<SiteScan.Provider
Expand Down Expand Up @@ -305,4 +310,5 @@ SiteScanContextProvider.propTypes = {
scannableUrlsRestPath: PropTypes.string,
validateNonce: PropTypes.string,
validateQueryVar: PropTypes.string,
ampFirst: PropTypes.bool,
};
1 change: 1 addition & 0 deletions assets/src/onboarding-wizard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export function Providers( { children } ) {
scannableUrlsRestPath={ SCANNABLE_URLS_REST_PATH }
validateNonce={ VALIDATE_NONCE }
validateQueryVar={ VALIDATE_QUERY_VAR }
ampFirst={ true }
>
{ children }
</SiteScanContextProvider>
Expand Down
1 change: 1 addition & 0 deletions assets/src/settings-page/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ function Providers( { children } ) {
scannableUrlsRestPath={ SCANNABLE_URLS_REST_PATH }
validateNonce={ VALIDATE_NONCE }
validateQueryVar={ VALIDATE_QUERY_VAR }
ampFirst={ false }
>
{ children }
</SiteScanContextProvider>
Expand Down

0 comments on commit 9b3f951

Please sign in to comment.