From 0193ad90bb6e75405412e99dcf764d945808dc0f Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Mon, 29 Jul 2024 09:32:12 +0200 Subject: [PATCH] Protected against quick escapes when loading post fix https://linear.app/tryghost/issue/SLO-180/typeerror-cannot-read-properties-of-null-reading-displayname - in the event you click on a post and then press Back really quickly, `this.post` will be null because the post is not loaded - the code here fails because it tries to read a property from `null` - we can protect against that by using optional chaining on the property --- ghost/admin/app/controllers/lexical-editor.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ghost/admin/app/controllers/lexical-editor.js b/ghost/admin/app/controllers/lexical-editor.js index ee15feab8f..71c6331437 100644 --- a/ghost/admin/app/controllers/lexical-editor.js +++ b/ghost/admin/app/controllers/lexical-editor.js @@ -871,11 +871,11 @@ export default class LexicalEditorController extends Controller { this.ui.updateDocumentTitle(); } - /* + /* // sync the post slug with the post title, except when: // - the user has already typed a custom slug, which should not be overwritten // - the post has been published, so that published URLs are not broken - */ + */ @enqueueTask *generateSlugTask() { const currentTitle = this.get('post.title'); @@ -916,7 +916,7 @@ export default class LexicalEditorController extends Controller { *backgroundLoaderTask() { yield this.store.query('snippet', {limit: 'all'}); - if (this.post.displayName === 'page' && this.feature.get('collections') && this.feature.get('collectionsCard')) { + if (this.post?.displayName === 'page' && this.feature.get('collections') && this.feature.get('collectionsCard')) { yield this.store.query('collection', {limit: 'all'}); }