From 51b3e634725c436e11e89cefa0942e441be9912d Mon Sep 17 00:00:00 2001 From: JzoNg Date: Wed, 13 May 2026 14:14:53 +0800 Subject: [PATCH] fix(web): add input field crash --- .../hitl-input-block-replacement-block.tsx | 43 ++++++++++++++++++- .../prompt-editor/prompt-editor-content.tsx | 9 ++-- .../human-input/components/form-content.tsx | 4 +- 3 files changed, 47 insertions(+), 9 deletions(-) diff --git a/web/app/components/base/prompt-editor/plugins/hitl-input-block/hitl-input-block-replacement-block.tsx b/web/app/components/base/prompt-editor/plugins/hitl-input-block/hitl-input-block-replacement-block.tsx index ebb7d9a895..d6431f81d6 100644 --- a/web/app/components/base/prompt-editor/plugins/hitl-input-block/hitl-input-block-replacement-block.tsx +++ b/web/app/components/base/prompt-editor/plugins/hitl-input-block/hitl-input-block-replacement-block.tsx @@ -9,6 +9,7 @@ import { useCallback, useEffect, useMemo, + useRef, } from 'react' import { HITL_INPUT_REG } from '@/config' import { decoratorTransform } from '../../utils' @@ -39,6 +40,32 @@ const HITLInputReplacementBlock = ({ acc.push(...curr.vars.filter(v => v.isRagVariable)) return acc }, []), [variables]) + const latestConfigRef = useRef({ + nodeId, + formInputs, + onFormInputsChange, + onFormInputItemRename, + onFormInputItemRemove, + workflowNodesMap, + getVarType, + environmentVariables, + conversationVariables, + ragVariables, + readonly, + }) + latestConfigRef.current = { + nodeId, + formInputs, + onFormInputsChange, + onFormInputItemRename, + onFormInputItemRemove, + workflowNodesMap, + getVarType, + environmentVariables, + conversationVariables, + ragVariables, + readonly, + } useEffect(() => { if (!editor.hasNodes([HITLInputNode])) @@ -47,6 +74,20 @@ const HITLInputReplacementBlock = ({ const createHITLInputBlockNode = useCallback((textNode: TextNode): HITLInputNode => { const varName = textNode.getTextContent().split('.')[1]!.replace(/#\}\}$/, '') + const { + nodeId, + formInputs, + onFormInputsChange, + onFormInputItemRename, + onFormInputItemRemove, + workflowNodesMap, + getVarType, + environmentVariables, + conversationVariables, + ragVariables, + readonly, + } = latestConfigRef.current + return $applyNodeReplacement($createHITLInputNode( varName, nodeId, @@ -61,7 +102,7 @@ const HITLInputReplacementBlock = ({ ragVariables, readonly, )) - }, [nodeId, formInputs, onFormInputsChange, onFormInputItemRename, onFormInputItemRemove, workflowNodesMap, getVarType, environmentVariables, conversationVariables, ragVariables, readonly]) + }, []) const getMatch = useCallback((text: string) => { const matchArr = REGEX.exec(text) diff --git a/web/app/components/base/prompt-editor/prompt-editor-content.tsx b/web/app/components/base/prompt-editor/prompt-editor-content.tsx index 28a0863284..efc7dda0c6 100644 --- a/web/app/components/base/prompt-editor/prompt-editor-content.tsx +++ b/web/app/components/base/prompt-editor/prompt-editor-content.tsx @@ -1,9 +1,6 @@ -import type { - EditorState, - LexicalCommand, -} from 'lexical' +import type { EditorState } from 'lexical' import type { FC } from 'react' -import type { Hotkey } from './plugins/shortcuts-popup-plugin' +import type { Hotkey, ShortcutPopupInsertHandler } from './plugins/shortcuts-popup-plugin' import type { ContextBlockType, CurrentBlockType, @@ -71,7 +68,7 @@ import { type ShortcutPopup = { hotkey: Hotkey - Popup: React.ComponentType<{ onClose: () => void, onInsert: (command: LexicalCommand, params: unknown[]) => void }> + Popup: React.ComponentType<{ onClose: () => void, onInsert: ShortcutPopupInsertHandler }> } type PromptEditorContentProps = { diff --git a/web/app/components/workflow/nodes/human-input/components/form-content.tsx b/web/app/components/workflow/nodes/human-input/components/form-content.tsx index 6293ac7f37..5faa347cd6 100644 --- a/web/app/components/workflow/nodes/human-input/components/form-content.tsx +++ b/web/app/components/workflow/nodes/human-input/components/form-content.tsx @@ -101,8 +101,8 @@ const FormContent: FC = ({ acc[node.id] = { title: node.data.title, type: node.data.type, - width: node.width, - height: node.height, + width: node.width ?? undefined, + height: node.height ?? undefined, position: node.position, } if (node.data.type === BlockEnum.Start) {