From 55d64b6d030f6031a0a20d7216b53d7f7cf2660b Mon Sep 17 00:00:00 2001 From: mortezaei Date: Fri, 21 Aug 2026 20:31:40 +0330 Subject: [PATCH] fix(birthplace): prevent country state from being overwritten when typing city --- src/components/Componentes/question-birthplace.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/components/Componentes/question-birthplace.tsx b/src/components/Componentes/question-birthplace.tsx index 6533db8..bc10c05 100644 --- a/src/components/Componentes/question-birthplace.tsx +++ b/src/components/Componentes/question-birthplace.tsx @@ -182,6 +182,8 @@ export function QuestionBirthplace({ return () => window.removeEventListener("keydown", handleKeyDown); }, [isOpen, closeSheet]); + const lastInternalAnswerRef = useRef(null); + const updateAnswers = (country: string, city: string) => { const cleanCountry = country?.trim() || ""; const cleanCity = city?.trim() || ""; @@ -189,6 +191,7 @@ export function QuestionBirthplace({ cleanCity && cleanCountry ? `${cleanCity}, ${cleanCountry}` : cleanCity || cleanCountry || null; + lastInternalAnswerRef.current = formatted; setAnswerValue(question, formatted); }; @@ -266,8 +269,11 @@ export function QuestionBirthplace({ updateAnswers(country, city); }; - // Synchronize state if rawValue changes externally + // Synchronize state ONLY if rawValue changes externally (e.g. draft fetch or reset) useEffect(() => { + if (rawValue === lastInternalAnswerRef.current) { + return; + } const updated = parseValue(rawValue); const resolvedC = resolveCountryName(updated.country, locale); if (resolvedC && resolvedC !== selectedCountry) {