Skip to content

Commit

Permalink
Edit Site: Add a loading timeout (WordPress#51049)
Browse files Browse the repository at this point in the history
* Edit Site: Add a loading timeout

* Set maximum loading time to 10s
  • Loading branch information
tyxla authored and sethrubenstein committed Jul 13, 2023
1 parent 8e7163b commit ec0d2af
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions packages/edit-site/src/components/layout/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { store as coreStore } from '@wordpress/core-data';
*/
import useEditedEntityRecord from '../use-edited-entity-record';

const MAX_LOADING_TIME = 10000; // 10 seconds

export function useIsSiteEditorLoading() {
const { isLoaded: hasLoadedPost } = useEditedEntityRecord();
const [ loaded, setLoaded ] = useState( false );
Expand All @@ -22,6 +24,25 @@ export function useIsSiteEditorLoading() {
[ loaded ]
);

/*
* If the maximum expected loading time has passed, we're marking the
* editor as loaded, in order to prevent any failed requests from blocking
* the editor canvas from appearing.
*/
useEffect( () => {
let timeout;

if ( ! loaded ) {
timeout = setTimeout( () => {
setLoaded( true );
}, MAX_LOADING_TIME );
}

return () => {
clearTimeout( timeout );
};
}, [ loaded ] );

useEffect( () => {
if ( inLoadingPause ) {
/*
Expand Down

0 comments on commit ec0d2af

Please sign in to comment.