From 0a8d25fae28a362af8dcadf3955c9fb3db76ff84 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Thu, 28 Sep 2017 13:53:22 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=20Fixed=20incorrect=20autosave?= =?UTF-8?q?=20of=20published=20posts=20when=20leaving=20editor=20(#879)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes https://github.com/TryGhost/Ghost/issues/9072 - the checks when leaving the editor were detecting that the autosave tasks were running and so forcing an immediate autosave even though the autosave tasks wouldn't do anything - exit early from autosave tasks if autosave isn't allowed --- .../app/mixins/editor-base-controller.js | 20 ++++++++++--------- ghost/admin/app/mixins/editor-base-route.js | 6 ++---- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/ghost/admin/app/mixins/editor-base-controller.js b/ghost/admin/app/mixins/editor-base-controller.js index 2d32596cef..cf41e7e591 100644 --- a/ghost/admin/app/mixins/editor-base-controller.js +++ b/ghost/admin/app/mixins/editor-base-controller.js @@ -71,27 +71,29 @@ export default Mixin.create({ // save 3 seconds after the last edit _autosave: task(function* () { + if (!this.get('_canAutosave')) { + return; + } + // force an instant save on first body edit for new posts - if (this.get('_canAutosave') && this.get('model.isNew')) { + if (this.get('model.isNew')) { return this.get('autosave').perform(); } yield timeout(AUTOSAVE_TIMEOUT); - - if (this.get('_canAutosave')) { - this.get('autosave').perform(); - } + this.get('autosave').perform(); }).restartable(), // save at 60 seconds even if the user doesn't stop typing _timedSave: task(function* () { + if (!this.get('_canAutosave')) { + return; + } + // eslint-disable-next-line no-constant-condition while (!testing && true) { yield timeout(TIMEDSAVE_TIMEOUT); - - if (this.get('_canAutosave')) { - this.get('autosave').perform(); - } + this.get('autosave').perform(); } }).drop(), diff --git a/ghost/admin/app/mixins/editor-base-route.js b/ghost/admin/app/mixins/editor-base-route.js index 224e948628..3be3a2730c 100644 --- a/ghost/admin/app/mixins/editor-base-route.js +++ b/ghost/admin/app/mixins/editor-base-route.js @@ -39,20 +39,18 @@ export default Mixin.create(styleBody, ShortcutsRoute, { let controllerIsDirty = controller.get('hasDirtyAttributes'); let model = controller.get('model'); let state = model.getProperties('isDeleted', 'isSaving', 'hasDirtyAttributes', 'isNew'); - let deletedWithoutChanges, - fromNewToEdit; if (this.get('upgradeStatus.isRequired')) { return this._super(...arguments); } - fromNewToEdit = this.get('routeName') === 'editor.new' + let fromNewToEdit = this.get('routeName') === 'editor.new' && transition.targetName === 'editor.edit' && transition.intent.contexts && transition.intent.contexts[0] && transition.intent.contexts[0].id === model.get('id'); - deletedWithoutChanges = state.isDeleted + let deletedWithoutChanges = state.isDeleted && (state.isSaving || !state.hasDirtyAttributes); if (!fromNewToEdit && !deletedWithoutChanges && controllerIsDirty) {