Skip to content

Commit

Permalink
Edit Site: Add a loading timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla committed Jun 8, 2023
1 parent f1d0bd5 commit 5447fd9
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 = 30000; // 30 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 5447fd9

Please sign in to comment.