diff --git a/web/app/components/base/prompt-editor/plugins/on-blur-or-focus-block.tsx b/web/app/components/base/prompt-editor/plugins/on-blur-or-focus-block.tsx index 84eacb01ed..80c3ddba21 100644 --- a/web/app/components/base/prompt-editor/plugins/on-blur-or-focus-block.tsx +++ b/web/app/components/base/prompt-editor/plugins/on-blur-or-focus-block.tsx @@ -20,17 +20,21 @@ const OnBlurBlock: FC = ({ }) => { const [editor] = useLexicalComposerContext() - const ref = useRef(null) + const ref = useRef | null>(null) useEffect(() => { - return mergeRegister( + const clearHideMenuTimeout = () => { + if (ref.current) { + clearTimeout(ref.current) + ref.current = null + } + } + + const unregister = mergeRegister( editor.registerCommand( CLEAR_HIDE_MENU_TIMEOUT, () => { - if (ref.current) { - clearTimeout(ref.current) - ref.current = null - } + clearHideMenuTimeout() return true }, COMMAND_PRIORITY_EDITOR, @@ -41,6 +45,7 @@ const OnBlurBlock: FC = ({ // Check if the clicked target element is var-search-input const target = event?.relatedTarget as HTMLElement if (!target?.classList?.contains('var-search-input')) { + clearHideMenuTimeout() ref.current = setTimeout(() => { editor.dispatchCommand(KEY_ESCAPE_COMMAND, new KeyboardEvent('keydown', { key: 'Escape' })) }, 200) @@ -61,6 +66,11 @@ const OnBlurBlock: FC = ({ COMMAND_PRIORITY_EDITOR, ), ) + + return () => { + clearHideMenuTimeout() + unregister() + } }, [editor, onBlur, onFocus]) return null diff --git a/web/eslint-suppressions.json b/web/eslint-suppressions.json index 1c9e9d43f6..b7f18c3d3c 100644 --- a/web/eslint-suppressions.json +++ b/web/eslint-suppressions.json @@ -3624,11 +3624,6 @@ "count": 2 } }, - "app/components/base/prompt-editor/plugins/on-blur-or-focus-block.tsx": { - "ts/no-explicit-any": { - "count": 1 - } - }, "app/components/base/prompt-editor/plugins/query-block/index.tsx": { "react-refresh/only-export-components": { "count": 2