From 02232c0ca38bc8361661ccaecb6d52abeafa8ac3 Mon Sep 17 00:00:00 2001 From: Henry Heino <46334387+personalizedrefrigerator@users.noreply.github.com> Date: Sun, 24 Dec 2023 06:54:24 -0800 Subject: [PATCH] Mobile: Fixes #9502: Fix note editor crash when trying to edit text quickly after opening a note (#9581) --- packages/app-mobile/components/screens/Note.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/app-mobile/components/screens/Note.tsx b/packages/app-mobile/components/screens/Note.tsx index 57ad7c5bb..57f8922a0 100644 --- a/packages/app-mobile/components/screens/Note.tsx +++ b/packages/app-mobile/components/screens/Note.tsx @@ -1347,7 +1347,9 @@ class NoteScreenComponent extends BaseScreenComponent implements B let fieldToFocus = this.state.note.is_todo ? 'title' : 'body'; if (this.state.mode === 'view') fieldToFocus = ''; - if (fieldToFocus === 'title' && this.titleTextFieldRef.current) { + // Avoid writing `this.titleTextFieldRef.current` -- titleTextFieldRef may + // be undefined. + if (fieldToFocus === 'title' && this.titleTextFieldRef?.current) { this.titleTextFieldRef.current.focus(); } // if (fieldToFocus === 'body' && this.markdownEditorRef.current) {