Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix: PromptEditor leaves a pending blur timer that triggers a Vitest unhandled error (#33253)

GuanMu8fe376848f1c
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 84eacb01edd..80c3ddba21b 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<OnBlurBlockProps> = ({
}) => {
const [editor] = useLexicalComposerContext()
- const ref = useRef<any>(null)
+ const ref = useRef<ReturnType<typeof setTimeout> | 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<OnBlurBlockProps> = ({
// 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<OnBlurBlockProps> = ({
COMMAND_PRIORITY_EDITOR,
),
)
+
+ return () => {
+ clearHideMenuTimeout()
+ unregister()
+ }
}, [editor, onBlur, onFocus])
return null
diff --git a/web/eslint-suppressions.json b/web/eslint-suppressions.json
index 1c9e9d43f6d..b7f18c3d3c2 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