From 841cd2d277ef44574632087469efa88f38816879 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] =?UTF-8?q?fix(ui):=20prevent=20system=5Fprompt=5Ftemplate?= =?UTF-8?q?=20overwrite=20when=20value=20is=20empty=20string=20##=20Proble?= =?UTF-8?q?m=20When=20editing=20trader=20configuration,=20if=20`system=5Fp?= =?UTF-8?q?rompt=5Ftemplate`=20was=20set=20to=20an=20empty=20string=20("")?= =?UTF-8?q?,=20the=20UI=20would=20incorrectly=20treat=20it=20as=20falsy=20?= =?UTF-8?q?and=20overwrite=20it=20with=20'default',=20losing=20the=20user'?= =?UTF-8?q?s=20selection.=20**Root=20cause:**=20```tsx=20if=20(traderData?= =?UTF-8?q?=20&&=20!traderData.system=5Fprompt=5Ftemplate)=20{=20=20=20//?= =?UTF-8?q?=20=E2=9D=8C=20This=20triggers=20for=20both=20undefined=20AND?= =?UTF-8?q?=20empty=20string=20""=20=20=20setFormData({=20system=5Fprompt?= =?UTF-8?q?=5Ftemplate:=20'default'=20});=20}=20```=20JavaScript=20falsy?= =?UTF-8?q?=20values=20that=20trigger=20`!`=20operator:=20-=20`undefined`?= =?UTF-8?q?=20=E2=9C=85=20Should=20trigger=20default=20-=20`null`=20?= =?UTF-8?q?=E2=9C=85=20Should=20trigger=20default=20-=20`""`=20=E2=9D=8C?= =?UTF-8?q?=20Should=20NOT=20trigger=20(user=20explicitly=20chose=20empty)?= =?UTF-8?q?=20-=20`false`,=20`0`,=20`NaN`=20(less=20relevant=20here)=20##?= =?UTF-8?q?=20Solution=20Change=20condition=20to=20explicitly=20check=20fo?= =?UTF-8?q?r=20`undefined`:=20```tsx=20if=20(traderData=20&&=20traderData.?= =?UTF-8?q?system=5Fprompt=5Ftemplate=20=3D=3D=3D=20undefined)=20{=20=20?= =?UTF-8?q?=20//=20=E2=9C=85=20Only=20triggers=20for=20truly=20missing=20f?= =?UTF-8?q?ield=20=20=20setFormData({=20system=5Fprompt=5Ftemplate:=20'def?= =?UTF-8?q?ault'=20});=20}=20```=20##=20Impact=20-=20=E2=9C=85=20Empty=20s?= =?UTF-8?q?tring=20selections=20are=20preserved=20-=20=E2=9C=85=20Legacy?= =?UTF-8?q?=20data=20(undefined)=20still=20gets=20default=20value=20-=20?= =?UTF-8?q?=E2=9C=85=20User's=20explicit=20choices=20are=20respected=20-?= =?UTF-8?q?=20=E2=9C=85=20No=20breaking=20changes=20to=20existing=20functi?= =?UTF-8?q?onality=20##=20Testing=20-=20=E2=9C=85=20Code=20compiles=20-=20?= =?UTF-8?q?=E2=9A=A0=EF=B8=8F=20Requires=20manual=20UI=20testing:=20=20=20?= =?UTF-8?q?-=20[=20]=20Edit=20trader=20with=20empty=20system=5Fprompt=5Fte?= =?UTF-8?q?mplate=20=20=20-=20[=20]=20Verify=20it=20doesn't=20reset=20to?= =?UTF-8?q?=20'default'=20=20=20-=20[=20]=20Create=20new=20trader=20?= =?UTF-8?q?=E2=86=92=20should=20default=20to=20'default'=20=20=20-=20[=20]?= =?UTF-8?q?=20Edit=20old=20trader=20(undefined=20field)=20=E2=86=92=20shou?= =?UTF-8?q?ld=20default=20to=20'default'=20##=20Code=20Changes=20```=20web?= =?UTF-8?q?/src/components/TraderConfigModal.tsx:=20-=20Line=2099:=20Chang?= =?UTF-8?q?ed=20!traderData.system=5Fprompt=5Ftemplate=20=E2=86=92=20=3D?= =?UTF-8?q?=3D=3D=20undefined=20```?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 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'