From 7bd02b7939f78cf9ab6792c7bce97c7b08360a05 Mon Sep 17 00:00:00 2001 From: ZhouYongyou <128128010+zhouyongyou@users.noreply.github.com> Date: Tue, 4 Nov 2025 19:00:23 +0800 Subject: [PATCH] fix(ui): prevent system_prompt_template overwrite when value is empty string MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Problem When editing trader configuration, if `system_prompt_template` was set to an empty string (""), the UI would incorrectly treat it as falsy and overwrite it with 'default', losing the user's selection. **Root cause:** ```tsx if (traderData && !traderData.system_prompt_template) { // ❌ This triggers for both undefined AND empty string "" setFormData({ system_prompt_template: 'default' }); } ``` JavaScript falsy values that trigger `!` operator: - `undefined` ✅ Should trigger default - `null` ✅ Should trigger default - `""` ❌ Should NOT trigger (user explicitly chose empty) - `false`, `0`, `NaN` (less relevant here) ## Solution Change condition to explicitly check for `undefined`: ```tsx if (traderData && traderData.system_prompt_template === undefined) { // ✅ Only triggers for truly missing field setFormData({ system_prompt_template: 'default' }); } ``` ## Impact - ✅ Empty string selections are preserved - ✅ Legacy data (undefined) still gets default value - ✅ User's explicit choices are respected - ✅ No breaking changes to existing functionality ## Testing - ✅ Code compiles - ⚠️ Requires manual UI testing: - [ ] Edit trader with empty system_prompt_template - [ ] Verify it doesn't reset to 'default' - [ ] Create new trader → should default to 'default' - [ ] Edit old trader (undefined field) → should default to 'default' ## Code Changes ``` web/src/components/TraderConfigModal.tsx: - Line 99: Changed !traderData.system_prompt_template → === undefined ``` --- web/src/components/TraderConfigModal.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/components/TraderConfigModal.tsx b/web/src/components/TraderConfigModal.tsx index 4676c194..4f9ddc72 100644 --- a/web/src/components/TraderConfigModal.tsx +++ b/web/src/components/TraderConfigModal.tsx @@ -96,7 +96,7 @@ export function TraderConfigModal({ }); } // 确保旧数据也有默认的 system_prompt_template - if (traderData && !traderData.system_prompt_template) { + if (traderData && traderData.system_prompt_template === undefined) { setFormData(prev => ({ ...prev, system_prompt_template: 'default'