diff --git a/CHANGELOG.md b/CHANGELOG.md index 98708f62b..214abbbb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Version 1.1.4 - Various performance improvements +- Fix bio editor crashing when faced with commet bio format. ## Version 1.1.3 diff --git a/src/app/features/settings/account/BioEditor.tsx b/src/app/features/settings/account/BioEditor.tsx index 04c6c45b2..e62ae0bec 100644 --- a/src/app/features/settings/account/BioEditor.tsx +++ b/src/app/features/settings/account/BioEditor.tsx @@ -18,7 +18,7 @@ import { SettingTile } from '../../../components/setting-tile'; import * as css from './BioEditor.css'; type BioEditorProps = { - value?: string; + value?: string | any; isSaving?: boolean; imagePackRooms?: any[]; onSave: (htmlContent: string) => void; @@ -67,15 +67,23 @@ export function BioEditor({ value, isSaving, imagePackRooms, onSave }: BioEditor if (valueChanged || isFirstValidLoad) { prevValue.current = value; - const incomingPlainText = value ? toPlainText(htmlToEditorInput(value, isMarkdown), isMarkdown).trim() : ''; + + let normalizedValue = value; + if (typeof normalizedValue === 'object' && normalizedValue !== null && 'formatted_body' in normalizedValue) { + normalizedValue = normalizedValue.formatted_body; + } + + const safeValue = typeof normalizedValue === 'string' ? normalizedValue : ''; + + const incomingPlainText = toPlainText(htmlToEditorInput(safeValue, isMarkdown), isMarkdown).trim(); const currentPlainText = toPlainText(editor.children, isMarkdown).trim(); if (currentPlainText === incomingPlainText && initialized.current) return; - const isLikelyHtml = value?.includes('<') || value?.includes('>'); + const isLikelyHtml = safeValue.includes('<') || safeValue.includes('>'); const initialValue = isLikelyHtml - ? htmlToEditorInput(value!, isMarkdown) - : plainToEditorInput(value ?? '', isMarkdown); + ? htmlToEditorInput(safeValue, isMarkdown) + : plainToEditorInput(safeValue, isMarkdown); editor.children = initialValue; Editor.normalize(editor, { force: true }); diff --git a/src/app/features/settings/account/Profile.tsx b/src/app/features/settings/account/Profile.tsx index 28a6196be..8c2c4d254 100644 --- a/src/app/features/settings/account/Profile.tsx +++ b/src/app/features/settings/account/Profile.tsx @@ -25,7 +25,7 @@ import { Spinner, } from 'folds'; import FocusTrap from 'focus-trap-react'; -import { MatrixClient } from 'matrix-js-sdk'; +import { useSetAtom } from 'jotai'; import { SequenceCard } from '../../../components/sequence-card'; import { SequenceCardStyle } from '../styles.css'; import { SettingTile } from '../../../components/setting-tile'; @@ -48,7 +48,6 @@ import { TimezoneEditor } from './TimezoneEditor'; import { PronounEditor } from './PronounEditor'; import { BioEditor } from './BioEditor'; import { NameColorEditor } from './NameColorEditor'; -import { useSetAtom } from 'jotai'; import { profilesCacheAtom } from '../../../state/userRoomProfile'; type PronounSet = {