diff --git a/packages/netlify-cms-core/src/actions/entries.ts b/packages/netlify-cms-core/src/actions/entries.ts index 7909737f..5c2f7abc 100644 --- a/packages/netlify-cms-core/src/actions/entries.ts +++ b/packages/netlify-cms-core/src/actions/entries.ts @@ -313,12 +313,13 @@ export function deleteLocalBackup(collection: Collection, slug: string) { */ export function loadEntry(collection: Collection, slug: string) { - return (dispatch: ThunkDispatch, getState: () => State) => { + return async (dispatch: ThunkDispatch, getState: () => State) => { const state = getState(); const backend = currentBackend(state.config); + await waitForMediaLibraryToLoad(dispatch, getState()); dispatch(entryLoading(collection, slug)); return backend - .getEntry(state, collection, slug) + .getEntry(getState(), collection, slug) .then((loadedEntry: EntryValue) => { return dispatch(entryLoaded(collection, loadedEntry)); }) diff --git a/packages/netlify-cms-core/src/actions/mediaLibrary.ts b/packages/netlify-cms-core/src/actions/mediaLibrary.ts index f33f5ed6..21babcb2 100644 --- a/packages/netlify-cms-core/src/actions/mediaLibrary.ts +++ b/packages/netlify-cms-core/src/actions/mediaLibrary.ts @@ -147,26 +147,28 @@ export function loadMedia( } } dispatch(mediaLoading(page)); - return new Promise(resolve => { - setTimeout( - () => - resolve( - backend - .getMedia() - .then(files => dispatch(mediaLoaded(files))) - .catch((error: { status?: number }) => { - console.error(error); - if (error.status === 404) { - console.log('This 404 was expected and handled appropriately.'); - dispatch(mediaLoaded([])); - } else { - dispatch(mediaLoadFailed()); - } - }), - ), - delay, - ); - }); + + const loadFunction = () => + backend + .getMedia() + .then(files => dispatch(mediaLoaded(files))) + .catch((error: { status?: number }) => { + console.error(error); + if (error.status === 404) { + console.log('This 404 was expected and handled appropriately.'); + dispatch(mediaLoaded([])); + } else { + dispatch(mediaLoadFailed()); + } + }); + + if (delay > 0) { + return new Promise(resolve => { + setTimeout(() => resolve(loadFunction()), delay); + }); + } else { + return loadFunction(); + } }; }