Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use fetch instead of apiFetch. #9936

Merged
merged 10 commits into from
Jan 6, 2025
13 changes: 4 additions & 9 deletions assets/js/hooks/useMonitorInternetConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { useLifecycles, useInterval } from 'react-use';
/**
* WordPress dependencies
*/
import apiFetch from '@wordpress/api-fetch';
import { useCallback } from '@wordpress/element';

/**
Expand All @@ -33,6 +32,8 @@ import { useCallback } from '@wordpress/element';
import { useSelect, useDispatch } from 'googlesitekit-data';
import { CORE_UI } from '../googlesitekit/datastore/ui/constants';

const { rootURL } = global._googlesitekitAPIFetchData || {};

/**
* Monitors the user's internet connection status.
*
Expand All @@ -53,15 +54,9 @@ export function useMonitorInternetConnection() {
}

try {
const connectionCheckResponse = await apiFetch( {
path: '/google-site-kit/v1/',
} );

// We are only interested if the request was successful, to
// confirm online status.
const canReachConnectionCheck = !! connectionCheckResponse;
await fetch( `${ rootURL }google-site-kit/v1/` );
aaemnnosttv marked this conversation as resolved.
Show resolved Hide resolved

setIsOnline( canReachConnectionCheck );
setIsOnline( true );
} catch ( err ) {
setIsOnline( false );
}
Expand Down
4 changes: 3 additions & 1 deletion assets/js/hooks/useMonitorInternetConnection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import {
import { CORE_UI } from '../googlesitekit/datastore/ui/constants';
import { useMonitorInternetConnection } from './useMonitorInternetConnection';

const { rootURL } = global._googlesitekitAPIFetchData || {};

describe( 'useMonitorInternetConnection', () => {
let registry;
let store;
Expand All @@ -40,7 +42,7 @@ describe( 'useMonitorInternetConnection', () => {
} );
};

const connectionCheckEndpoint = '/google-site-kit/v1/?_locale=user';
const connectionCheckEndpoint = `${ rootURL }google-site-kit/v1/`;
aaemnnosttv marked this conversation as resolved.
Show resolved Hide resolved

const connectionCheckResponse = {
namespace: 'google-site-kit/v1',
Expand Down
Loading