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.
This commit is contained in:
iliya 2026-03-28 16:44:26 +02:00
parent 6b09b59d88
commit daef2db07c

View file

@ -380,6 +380,12 @@ const ToolInputPreview = ({
toolInput: Record<string, unknown>;
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 (
<div className="px-4 py-2.5">
<div