diff --git a/src/app/components/editor/Editor.tsx b/src/app/components/editor/Editor.tsx index ddab1cd81..e72605001 100644 --- a/src/app/components/editor/Editor.tsx +++ b/src/app/components/editor/Editor.tsx @@ -23,7 +23,13 @@ import { CustomElement } from './slate'; import * as css from './Editor.css'; import { toggleKeyboardShortcut } from './keyboard'; -const initialValue: CustomElement[] = [ +// One FRESH value per editor instance. slate-react keys its node→path weak +// maps by node object identity, so a module-level constant shared by every +// (main composer + thread composer + message editor) makes the second +// mount hijack the first editor's nodes and the first editor throws "Unable to +// find the path for Slate node" on its next render — the app-wide crash when +// opening a thread on a pristine composer (Gitea #165 / #184). +const createInitialValue = (): CustomElement[] => [ { type: BlockType.Paragraph, children: [{ text: '' }], @@ -92,6 +98,7 @@ export const CustomEditor = forwardRef( }, ref, ) => { + const [initialValue] = useState(createInitialValue); const renderElement = useCallback( (props: RenderElementProps) => , [],