From daef2db07c73aed661152e97aef2f7f096381fbf Mon Sep 17 00:00:00 2001 From: iliya Date: Sat, 28 Mar 2026 16:44:26 +0200 Subject: [PATCH] fix(team): prevent hooks ordering crash in ToolInputPreview Move useMemo/variable declarations BEFORE the AskUserQuestion early return to ensure hooks are called in consistent order regardless of which tool type is being displayed. --- src/renderer/components/team/ToolApprovalSheet.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/renderer/components/team/ToolApprovalSheet.tsx b/src/renderer/components/team/ToolApprovalSheet.tsx index 535ba772..a5d9c15e 100644 --- a/src/renderer/components/team/ToolApprovalSheet.tsx +++ b/src/renderer/components/team/ToolApprovalSheet.tsx @@ -380,6 +380,12 @@ const ToolInputPreview = ({ toolInput: Record; projectPath?: string; }): React.JSX.Element => { + const text = renderToolInput(toolName, toolInput, projectPath); + const fileName = getToolInputFileName(toolName, toolInput); + const lines = useMemo(() => highlightLines(text, fileName), [text, fileName]); + const rawFilePath = typeof toolInput.file_path === 'string' ? toolInput.file_path : null; + const isFileTool = FILE_TOOLS.has(toolName) && rawFilePath; + // AskUserQuestion: render questions with options as readable UI if (toolName === 'AskUserQuestion' && Array.isArray(toolInput.questions)) { const questions = toolInput.questions as { @@ -452,12 +458,6 @@ const ToolInputPreview = ({ ); } - const text = renderToolInput(toolName, toolInput, projectPath); - const fileName = getToolInputFileName(toolName, toolInput); - const lines = useMemo(() => highlightLines(text, fileName), [text, fileName]); - const rawFilePath = typeof toolInput.file_path === 'string' ? toolInput.file_path : null; - const isFileTool = FILE_TOOLS.has(toolName) && rawFilePath; - return (