1
0
mirror of https://github.com/mattermost/focalboard.git synced 2024-12-21 13:38:56 +02:00

Stopped reacting to initial text changes and not being a controlled component (#4039)

This commit is contained in:
Harshil Sharma 2022-10-19 20:54:13 +05:30 committed by GitHub
parent cb4e5d9c39
commit 38eaf5344e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -138,6 +138,7 @@ const MarkdownEditorInput = (props: Props): ReactElement => {
}, [board, editorState]) }, [board, editorState])
const [initialTextCache, setInitialTextCache] = useState<string | undefined>(initialText) const [initialTextCache, setInitialTextCache] = useState<string | undefined>(initialText)
const [initialTextUsed, setInitialTextUsed] = useState<boolean>(false)
// avoiding stale closure // avoiding stale closure
useEffect(() => { useEffect(() => {
@ -146,9 +147,16 @@ const MarkdownEditorInput = (props: Props): ReactElement => {
// for this if condition here, mentions don't work. I suspect it's because without // for this if condition here, mentions don't work. I suspect it's because without
// the in condition, we're changing editor state twice during component initialization // the in condition, we're changing editor state twice during component initialization
// and for some reason it causes mentions to not show up. // and for some reason it causes mentions to not show up.
if (initialText && initialText !== initialTextCache) {
// initial text should only be used once, i'e', initially
// `initialTextUsed` flag records if the initialText prop has been used
// to se the editor state once as a truthy value.
// Once used, we don't react to its changing value
if (!initialTextUsed && initialText && initialText !== initialTextCache) {
setEditorState(generateEditorState(initialText || '')) setEditorState(generateEditorState(initialText || ''))
setInitialTextCache(initialText) setInitialTextCache(initialText)
setInitialTextUsed(true)
} }
}, [initialText]) }, [initialText])