From a8342e153e536545f88cb4366be2c3fd1c06a3b2 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Mon, 3 Jun 2024 16:38:51 +0100 Subject: [PATCH] Fixed subtitle error being sticky closes https://linear.app/tryghost/issue/MOM-182 - we were seeing some odd behaviour with the validation engine when validating individual properties that meant our tracked property wasn't auto-updating on subtitle change after a body edit/autosave event - switched to a manually tracked property that's updated based on the validate call status --- ghost/admin/app/controllers/lexical-editor.js | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/ghost/admin/app/controllers/lexical-editor.js b/ghost/admin/app/controllers/lexical-editor.js index 232bd144ab..071f44747e 100644 --- a/ghost/admin/app/controllers/lexical-editor.js +++ b/ghost/admin/app/controllers/lexical-editor.js @@ -26,6 +26,7 @@ import {isHostLimitError, isServerUnreachableError, isVersionMismatchError} from import {isInvalidError} from 'ember-ajax/errors'; import {mobiledocToLexical} from '@tryghost/kg-converters'; import {inject as service} from '@ember/service'; +import {tracked} from '@glimmer/tracking'; const DEFAULT_TITLE = '(Untitled)'; // suffix that is applied to the title of a post when it has been duplicated @@ -158,6 +159,8 @@ export default class LexicalEditorController extends Controller { @inject config; + @tracked excerptErrorMessage = ''; + /* public properties -----------------------------------------------------*/ shouldFocusTitle = false; @@ -299,13 +302,19 @@ export default class LexicalEditorController extends Controller { } @action - updateExcerpt(excerpt) { + async updateExcerpt(excerpt) { this.post.customExcerpt = excerpt; - this.post.validate({property: 'customExcerpt'}); - } - - get excerptErrorMessage() { - return this.post.errors.errorsFor('customExcerpt')?.[0]?.message; + try { + await this.post.validate({property: 'customExcerpt'}); + this.excerptErrorMessage = ''; + } catch (e) { + // validator throws undefined on validation error + if (e === undefined) { + this.excerptErrorMessage = this.post.errors.errorsFor('customExcerpt')?.[0]?.message; + return; + } + throw e; + } } // updates local willPublish/Schedule values, does not get applied to