Skip to content

Commit

Permalink
Edit Site: Add a loading timeout (#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 committed Jun 8, 2023
1 parent f1d0bd5 commit f6f0523
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

1 comment on commit f6f0523

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in f6f0523.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5212766817
📝 Reported issues:

Please sign in to comment.