From 3ec235bc56caf35076cf0f23f490cf00cae47801 Mon Sep 17 00:00:00 2001 From: Josh Perez <60019601+josh-signal@users.noreply.github.com> Date: Mon, 7 Aug 2023 16:31:18 -0400 Subject: [PATCH] Reorders useEffect so that draft content is retained --- ts/components/CompositionArea.tsx | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/ts/components/CompositionArea.tsx b/ts/components/CompositionArea.tsx index f721b8b37..1c505fc6d 100644 --- a/ts/components/CompositionArea.tsx +++ b/ts/components/CompositionArea.tsx @@ -483,20 +483,6 @@ export function CompositionArea({ [inputApiRef, onPickEmoji] ); - const previousConversationId = usePrevious(conversationId, conversationId); - useEffect(() => { - if (conversationId === previousConversationId) { - return; - } - - if (!draftText) { - inputApiRef.current?.setContents(''); - return; - } - - inputApiRef.current?.setContents(draftText, draftBodyRanges, true); - }, [conversationId, draftBodyRanges, draftText, previousConversationId]); - // We want to reset the state of Quill only if: // // - Our other device edits the message (edit history length would change) @@ -520,6 +506,20 @@ export function CompositionArea({ ); }, [draftBodyRanges, draftEditMessageBody, hasEditDraftChanged]); + const previousConversationId = usePrevious(conversationId, conversationId); + useEffect(() => { + if (conversationId === previousConversationId) { + return; + } + + if (!draftText) { + inputApiRef.current?.setContents(''); + return; + } + + inputApiRef.current?.setContents(draftText, draftBodyRanges, true); + }, [conversationId, draftBodyRanges, draftText, previousConversationId]); + const handleToggleLarge = useCallback(() => { setLarge(l => !l); }, [setLarge]);