From 3df506ec7a0761971d8f9820f7624f3f55d3c797 Mon Sep 17 00:00:00 2001 From: mortezaei Date: Sun, 30 Aug 2026 06:26:33 +0330 Subject: [PATCH] refactor(ui): optimize flutter loading signal and profile data freshness Update client components to signal readiness to the Flutter wrapper immediately upon mounting, rather than waiting for data hydration. Additionally, adjust profile query settings to prioritize fresh server-side data. - Force `useHabibWebReady(true)` in all client-side route components - Set `staleTime` to 0 in `useMarriageProfileQuery` to ensure fresh data on mount - Simplify `queryClient.setQueryData` logic in profile hook --- src/app/candidate-contact/candidate-contact-client.tsx | 5 ++--- src/app/new-match/new-match-client.tsx | 5 ++--- src/app/questions-list/questions-list-client.tsx | 5 ++--- src/app/request-accepted/request-accepted-client.tsx | 5 ++--- src/app/request-sent/request-sent-client.tsx | 5 ++--- src/app/terms/page.tsx | 5 ++--- src/hooks/marriage/use-profile-main.ts | 9 ++------- 7 files changed, 14 insertions(+), 25 deletions(-) diff --git a/src/app/candidate-contact/candidate-contact-client.tsx b/src/app/candidate-contact/candidate-contact-client.tsx index a5acd36..16f1961 100644 --- a/src/app/candidate-contact/candidate-contact-client.tsx +++ b/src/app/candidate-contact/candidate-contact-client.tsx @@ -63,9 +63,8 @@ export default function CandidateContactClient() { } }, [profile, router, locale]); - // Signal Flutter to lift its loading cover once profile is available or query finished. - const isVisuallyReady = Boolean(profile) || isFetched; - useHabibWebReady(isVisuallyReady); + // Signal Flutter to lift its loading cover immediately on mount + useHabibWebReady(true); const isRedirecting = useMemo(() => { if (!profile) return false; diff --git a/src/app/new-match/new-match-client.tsx b/src/app/new-match/new-match-client.tsx index 5ebfdbc..12f0044 100644 --- a/src/app/new-match/new-match-client.tsx +++ b/src/app/new-match/new-match-client.tsx @@ -611,9 +611,8 @@ export default function NewMatchClient() { } }, [profile, locale, router, isLoading, isFetched, isError]); - // Signal Flutter to lift its loading cover only once match summary is populated in DOM or query finished. - const isVisuallyReady = Boolean(profile?.match_summary) || isFetched || isError; - useHabibWebReady(isVisuallyReady); + // Signal Flutter to lift its loading cover immediately on mount + useHabibWebReady(true); const handleOpenProfile = async () => { // If profile has not yet completed its initial server fetch or is in flight: diff --git a/src/app/questions-list/questions-list-client.tsx b/src/app/questions-list/questions-list-client.tsx index 56b28c3..d49ab79 100644 --- a/src/app/questions-list/questions-list-client.tsx +++ b/src/app/questions-list/questions-list-client.tsx @@ -136,9 +136,8 @@ export default function QuestionsListClient() { void fetchGeoCountryCode(); }, []); - // Signal Flutter to lift its loading cover once the profile is available or query finished. - const isVisuallyReady = Boolean(profile) || isProfileFetched; - useHabibWebReady(isVisuallyReady); + // Signal Flutter to lift its loading cover immediately on mount + useHabibWebReady(true); const startMatchMutation = useStartMarriageMatchMutation({ onSuccess: () => { diff --git a/src/app/request-accepted/request-accepted-client.tsx b/src/app/request-accepted/request-accepted-client.tsx index 4eb6c6d..1e43a19 100644 --- a/src/app/request-accepted/request-accepted-client.tsx +++ b/src/app/request-accepted/request-accepted-client.tsx @@ -267,9 +267,8 @@ export default function RequestAcceptedClient() { } }, [profile, isFetched, router, locale, noContactReportedSuccess]); - // Signal Flutter to lift its loading cover only once profile is populated in DOM or query finished. - const isVisuallyReady = Boolean(profile) || isFetched; - useHabibWebReady(isVisuallyReady); + // Signal Flutter to lift its loading cover immediately on mount + useHabibWebReady(true); const handleOpenProfile = async () => { if (!isFetched || isFetching) { diff --git a/src/app/request-sent/request-sent-client.tsx b/src/app/request-sent/request-sent-client.tsx index b6e21f7..d3e80b8 100644 --- a/src/app/request-sent/request-sent-client.tsx +++ b/src/app/request-sent/request-sent-client.tsx @@ -57,9 +57,8 @@ export default function RequestSentClient() { } }, [profile, isFetched, locale, router]); - // Signal Flutter to lift its loading cover only once profile is populated in DOM or query finished. - const isVisuallyReady = Boolean(profile) || isFetched; - useHabibWebReady(isVisuallyReady); + // Signal Flutter to lift its loading cover immediately on mount + useHabibWebReady(true); const isRedirecting = useMemo(() => { if (!profile) return false; diff --git a/src/app/terms/page.tsx b/src/app/terms/page.tsx index 4ab90c7..f694391 100644 --- a/src/app/terms/page.tsx +++ b/src/app/terms/page.tsx @@ -18,9 +18,8 @@ export default function TermsRoute() { const router = useRouter(); const { locale, dictionary: t } = useI18n(); - // Signal Flutter to lift its loading cover once profile or fallback is ready. - const isVisuallyReady = Boolean(profile) || !isLoading || isError; - useHabibWebReady(isVisuallyReady); + // Signal Flutter to lift its loading cover immediately on mount + useHabibWebReady(true); useEffect(() => { if (!isLoading && profile) { diff --git a/src/hooks/marriage/use-profile-main.ts b/src/hooks/marriage/use-profile-main.ts index 4cb411e..3e846fc 100644 --- a/src/hooks/marriage/use-profile-main.ts +++ b/src/hooks/marriage/use-profile-main.ts @@ -77,10 +77,8 @@ export function useMarriageProfileQuery( queryClient.setQueryData(marriageQueryKeys.profile(), (old: any) => { if (!old) return initial; return { - ...old, ...initial, - active_case: initial.active_case ?? old.active_case, - match_summary: initial.match_summary ?? old.match_summary, + ...old, }; }); } @@ -93,12 +91,9 @@ export function useMarriageProfileQuery( }, [queryClient]); const query = useQuery({ - staleTime: 5 * 60 * 1000, + staleTime: 0, // Prioritize fresh server data from /api/marriage/profile/main/ on mount refetchOnWindowFocus: false, initialData: getInitialMarriageProfile as any, - // Native-injected initialData is a snapshot from app-launch time and can be - // incomplete (e.g. missing active_case). Marking it stale forces a fresh - // fetch on mount instead of trusting it for the whole staleTime window. initialDataUpdatedAt: 0, ...options, queryFn: getMarriageProfile,