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

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
GuanMu 2026-03-11 11:09:29 +08:00 committed by GitHub
parent d67f04f63e
commit 8fe376848f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 11 deletions

View File

@ -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

View File

@ -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