From a9e82b1f7ebe240b5627cbb9006b18917f3d0300 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Wed, 9 Oct 2019 10:53:57 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20"unsaved=20changes"=20mo?= =?UTF-8?q?dal=20when=20leaving=20a=20new=20post=20with=20no=20content=20(?= =?UTF-8?q?#1358)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit no issue - if you created a post by setting a title but did not enter anything into the editor body before trying to leave the editor you'd see an "unsaved changes" modal because the "scratch" value for the post mobiledoc is `null` but the post's real mobiledoc value is now a blank document as returned from the API - adds a conditional reset of the `post.scratch` value after a successful save if the scratch value is blank --- ghost/admin/app/controllers/editor.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ghost/admin/app/controllers/editor.js b/ghost/admin/app/controllers/editor.js index 1435486ae4..9fa3dac1c0 100644 --- a/ghost/admin/app/controllers/editor.js +++ b/ghost/admin/app/controllers/editor.js @@ -460,9 +460,14 @@ export default Controller.extend({ // NOTE: `updateTags` changes `hasDirtyAttributes => true`. // For a saved post it would otherwise be false. post.updateTags(); - this._previousTagNames = this._tagNames; + // update the scratch property if it's `null` and we get a blank mobiledoc + // back from the API - prevents "unsaved changes" modal on new+blank posts + if (!post.scratch) { + post.set('scratch', JSON.parse(JSON.stringify(post.get('mobiledoc')))); + } + // if the two "scratch" properties (title and content) match the post, // then it's ok to set hasDirtyAttributes to false // TODO: why is this necessary?