From 22f337f659309724a9bd3653f9fa03cc23f5841a Mon Sep 17 00:00:00 2001 From: elianiva <51877647+elianiva@users.noreply.github.com> Date: Fri, 9 May 2025 00:25:58 +0700 Subject: [PATCH 1/2] fix(prompts): save on blur to prevent race condition --- .../src/components/prompts/PromptsView.tsx | 55 ++++++++++++------- .../prompts/__tests__/PromptsView.test.tsx | 4 ++ 2 files changed, 39 insertions(+), 20 deletions(-) diff --git a/webview-ui/src/components/prompts/PromptsView.tsx b/webview-ui/src/components/prompts/PromptsView.tsx index b76eebbba0..0e938a3d15 100644 --- a/webview-ui/src/components/prompts/PromptsView.tsx +++ b/webview-ui/src/components/prompts/PromptsView.tsx @@ -431,6 +431,21 @@ const PromptsView = ({ onDone }: PromptsViewProps) => { }) } + // keep track the state of the textareas locally because we sync them with the backend + // on separate event + const [roleDefinitionValue, setRoleDefinitionValue] = useState(() => { + const customMode = findModeBySlug(visualMode, customModes) + const prompt = customModePrompts?.[visualMode] as PromptComponent + return customMode?.roleDefinition ?? prompt?.roleDefinition ?? getRoleDefinition(visualMode) + }) + const [customInstructionsValue, setCustomInstructionsValue] = useState(customInstructions || "") + const [globalCustomInstructionsValue, setGlobalCustomInstructionsValue] = useState(() => { + const customMode = findModeBySlug(visualMode, customModes) + const prompt = customModePrompts?.[visualMode] as PromptComponent + return customMode?.customInstructions ?? prompt?.customInstructions ?? getCustomInstructions(mode, customModes) + }) + const [supportPromptValue, setSupportPromptValue] = useState(getSupportPromptValue(activeSupportOption) || "") + return ( @@ -667,19 +682,15 @@ const PromptsView = ({ onDone }: PromptsViewProps) => { {t("prompts:roleDefinition.description")}