From c7f9a9eb5693b5f3f824d88f8fc33e2d3f9dca53 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 14 Nov 2023 11:08:32 -0600 Subject: [PATCH] ComposeForm: get text from the editorRef instead of component state Fixes https://gitlab.com/soapbox-pub/soapbox/-/issues/1563 --- src/features/compose/components/compose-form.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/features/compose/components/compose-form.tsx b/src/features/compose/components/compose-form.tsx index 456dab69a7..182707b683 100644 --- a/src/features/compose/components/compose-form.tsx +++ b/src/features/compose/components/compose-form.tsx @@ -1,5 +1,5 @@ import clsx from 'clsx'; -import { CLEAR_EDITOR_COMMAND, TextNode, type LexicalEditor } from 'lexical'; +import { CLEAR_EDITOR_COMMAND, TextNode, type LexicalEditor, $getRoot } from 'lexical'; import React, { Suspense, useCallback, useEffect, useRef, useState } from 'react'; import { defineMessages, FormattedMessage, useIntl } from 'react-intl'; import { Link, useHistory } from 'react-router-dom'; @@ -96,13 +96,13 @@ const ComposeForm = ({ id, shouldCondense, autoFocus, clickab const anyMedia = compose.media_attachments.size > 0; const [composeFocused, setComposeFocused] = useState(false); - const [text, setText] = useState(compose.text); const firstRender = useRef(true); const formRef = useRef(null); const spoilerTextRef = useRef(null); const editorRef = useRef(null); + const text = editorRef.current?.getEditorState().read(() => $getRoot().getTextContent()) ?? ''; const { isDraggedOver } = useDraggedFiles(formRef); const getClickableArea = () => { @@ -297,7 +297,6 @@ const ComposeForm = ({ id, shouldCondense, autoFocus, clickab autoFocus={shouldAutoFocus} hasPoll={hasPoll} handleSubmit={handleSubmit} - onChange={setText} onFocus={handleComposeFocus} onPaste={onPaste} />