Fixed a bug where mentions don't show up in descripotions (#2099)

This commit is contained in:
Harshil Sharma 2022-01-12 18:41:33 +05:30 committed by GitHub
parent 22aa8e591d
commit d86d5005f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -56,9 +56,19 @@ const MarkdownEditorInput = (props: Props): ReactElement => {
return generateEditorState(initialText)
})
const [initialTextCache, setInitialTextCache] = useState<string | undefined>(initialText)
// avoiding stale closure
useEffect(() => {
setEditorState(generateEditorState(initialText))
// only change editor state when initialText actually changes from one defined value to another.
// This is needed to make the mentions plugin work. For some reason, if we don't check
// 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
// and for some reason it causes mentions to not show up.
if (initialText && initialText !== initialTextCache) {
setEditorState(generateEditorState(initialText || ''))
setInitialTextCache(initialText)
}
}, [initialText])
const [isMentionPopoverOpen, setIsMentionPopoverOpen] = useState(false)