From c4b36b9064fb316b50cd90a84bdf8dde552d3c38 Mon Sep 17 00:00:00 2001 From: Ajay Bura <32841439+ajbura@users.noreply.github.com> Date: Wed, 29 Jul 2026 09:00:27 +0530 Subject: [PATCH] =?UTF-8?q?=E2=80=B8fix=20editor=20crash=20with=20opened?= =?UTF-8?q?=20thread=20room=20switch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/components/editor/Editor.tsx | 22 +++++++++---------- src/app/features/room/RoomInput.tsx | 10 +++------ src/app/features/room/hooks/useSendMessage.ts | 2 +- .../thread-selector/ThreadSelector.tsx | 1 - src/app/state/room/roomInputDrafts.ts | 2 +- 5 files changed, 15 insertions(+), 22 deletions(-) diff --git a/src/app/components/editor/Editor.tsx b/src/app/components/editor/Editor.tsx index bd848dd5..b869f247 100644 --- a/src/app/components/editor/Editor.tsx +++ b/src/app/components/editor/Editor.tsx @@ -20,17 +20,9 @@ import { import { withHistory } from 'slate-history'; import { BlockType } from './types'; import { RenderElement, RenderLeaf } from './Elements'; -import { CustomElement } from './slate'; import * as css from './Editor.css'; import { toggleKeyboardShortcut } from './keyboard'; -const initialValue: CustomElement[] = [ - { - type: BlockType.Paragraph, - children: [{ text: '' }], - }, -]; - const withInline = (editor: Editor): Editor => { const { isInline } = editor; @@ -59,13 +51,13 @@ export const useEditor = (): Editor => { export type EditorChangeHandler = (value: Descendant[]) => void; type CustomEditorProps = { - editableName?: string; top?: ReactNode; bottom?: ReactNode; before?: ReactNode; after?: ReactNode; maxHeight?: string; editor: Editor; + initialValue?: Descendant[]; placeholder?: string; onKeyDown?: KeyboardEventHandler; onKeyUp?: KeyboardEventHandler; @@ -75,13 +67,13 @@ type CustomEditorProps = { export const CustomEditor = forwardRef( ( { - editableName, top, bottom, before, after, maxHeight = '50vh', editor, + initialValue, placeholder, onKeyDown, onKeyUp, @@ -90,6 +82,13 @@ export const CustomEditor = forwardRef( }, ref ) => { + const [defaultValue] = useState(() => [ + { + type: BlockType.Paragraph, + children: [{ text: '' }], + }, + ]); + const renderElement = useCallback( (props: RenderElementProps) => , [] @@ -120,7 +119,7 @@ export const CustomEditor = forwardRef( return (
- + {top} {before && ( @@ -137,7 +136,6 @@ export const CustomEditor = forwardRef( hideTrack > ( useCallback((width) => setHideStickerBtn(width < 500), []) ); - useEffect(() => { - Transforms.insertFragment(editor, draft); - }, [editor, draft]); - useEffect( () => () => { if (!isEmptyEditor(editor)) { const parsedDraft = JSON.parse(JSON.stringify(editor.children)); setDraft(parsedDraft); } else { - setDraft([]); + setDraft(undefined); } resetEditor(editor); resetEditorHistory(editor); @@ -306,8 +302,8 @@ export const RoomInput = forwardRef( /> )} { const stickerUrl = mxcToHttp(ct.session.baseUrl, mxc, useAuthentication).url(); if (!stickerUrl) return; - const info = await getImageInfo( + const info = getImageInfo( await loadImageElement(stickerUrl), await getImageUrlBlob(stickerUrl) ); diff --git a/src/app/features/room/message/thread-selector/ThreadSelector.tsx b/src/app/features/room/message/thread-selector/ThreadSelector.tsx index 41bbc9b0..693612f2 100644 --- a/src/app/features/room/message/thread-selector/ThreadSelector.tsx +++ b/src/app/features/room/message/thread-selector/ThreadSelector.tsx @@ -63,7 +63,6 @@ export function ThreadSelector({ hour24Clock={hour24Clock} dateFormatString={dateFormatString} ts={latestEvent.origin_server_ts} - inheritPriority /> diff --git a/src/app/state/room/roomInputDrafts.ts b/src/app/state/room/roomInputDrafts.ts index f4d57415..13f9b489 100644 --- a/src/app/state/room/roomInputDrafts.ts +++ b/src/app/state/room/roomInputDrafts.ts @@ -34,7 +34,7 @@ export type RoomIdToMsgAction = roomId: string; }; -const createDraftAtom = () => atom([]); +const createDraftAtom = () => atom(undefined); export type DraftAtom = ReturnType; export const composerToDraftAtom = atomFamily(() => createDraftAtom());