diff --git a/ghost/admin/app/controllers/lexical-editor.js b/ghost/admin/app/controllers/lexical-editor.js index 3e5fcf7120..66f668d5b0 100644 --- a/ghost/admin/app/controllers/lexical-editor.js +++ b/ghost/admin/app/controllers/lexical-editor.js @@ -931,14 +931,20 @@ export default class LexicalEditorController extends Controller { return; } - // clean up blank cards when leaving the editor if we have a draft post - // - blank cards could be left around due to autosave triggering whilst - // a blank card is present then the user attempting to leave - // - will mark the post as dirty so it gets saved when transitioning - // TODO: not yet implemented in react editor - // if (this._koenig && post.isDraft) { - // this._koenig.cleanup(); - // } + // wait for any save to finish before continuing to avoid any issues + // with attempting a new save whilst another has requests in-flight + if (this.saveTask.isRunning) { + transition.abort(); + await this.saveTask.last; + return transition.retry(); + } + // extra handling for PSM-triggered save tasks that aren't captured above + // NOTE: we don't wait on `_savePostTask` as it's only used as a child task + if (this.savePostTask.isRunning) { + transition.abort(); + await this.savePostTask.last; + return transition.retry(); + } // user can enter the slug name and then leave the post page, // in such case we should wait until the slug would be saved on backend @@ -948,6 +954,15 @@ export default class LexicalEditorController extends Controller { return transition.retry(); } + // clean up blank cards when leaving the editor if we have a draft post + // - blank cards could be left around due to autosave triggering whilst + // a blank card is present then the user attempting to leave + // - will mark the post as dirty so it gets saved when transitioning + // TODO: not yet implemented in lexical editor + // if (this._koenig && post.isDraft) { + // this._koenig.cleanup(); + // } + let hasDirtyAttributes = this.hasDirtyAttributes; let state = post.getProperties('isDeleted', 'isSaving', 'hasDirtyAttributes', 'isNew'); @@ -1009,7 +1024,7 @@ export default class LexicalEditorController extends Controller { return; } else { this._leaveConfirmed = true; - transition.retry(); + return transition.retry(); } }