From 96df0e6796cc61529fac676e0ad2f2146875475f Mon Sep 17 00:00:00 2001 From: Test Date: Fri, 3 Apr 2026 15:13:06 +0200 Subject: [PATCH] fix: use useState for prevTitle tracking in TitleField MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace useRef with useState for the prevTitle comparison — this is the canonical React pattern for clearing derived state when props change, and ensures React properly schedules the re-render. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/components/TitleField.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/TitleField.tsx b/src/components/TitleField.tsx index 38ac01f5..8e41d046 100644 --- a/src/components/TitleField.tsx +++ b/src/components/TitleField.tsx @@ -19,13 +19,13 @@ function useOptimisticTitle(title: string, onTitleChange: (t: string) => void) { // [optimisticTitle, forPropTitle]: shown after commit until title prop catches up const [optimistic, setOptimistic] = useState<[string, string] | null>(null) const isFocusedRef = useRef(false) - const prevTitleRef = useRef(title) + const [prevTitle, setPrevTitle] = useState(title) // Reset local edit when the title prop changes (e.g. note switch). // This prevents a stale handleFocus closure from locking in the old note's title // when focus-editor fires before React re-renders with the new tab. - if (prevTitleRef.current !== title) { - prevTitleRef.current = title + if (prevTitle !== title) { + setPrevTitle(title) if (localValue !== null) setLocalValue(null) }