From 01d00ec183c57ffc272c152ed14c215c305cda97 Mon Sep 17 00:00:00 2001 From: Light1YT Date: Sat, 13 Jun 2026 12:47:18 +0500 Subject: [PATCH] fix(custom-pois): invalidate canonical parcel-analyze + parcel-poi-score keys (#1241) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit useCustomPois mutations инвалидировали ['analyze', cad], а такой key ни один useQuery не регистрирует. Canonical keys: ['parcel-analyze', cad, horizon] и ['parcel-poi-score', cad]. Все 3 onSuccess были silent no-ops → скор+breakdown stale после правок кастомных POI. Patch: analyzeKey → ['parcel-analyze', parcelCad] (prefix-only, TanStack covers all horizons), добавлен poiScoreKey, оба инвалидируются вместе. 82/82 frontend тестов зелёные. Closes #1241 --- frontend/src/hooks/useCustomPois.ts | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/frontend/src/hooks/useCustomPois.ts b/frontend/src/hooks/useCustomPois.ts index ef3e0fcb..958c518a 100644 --- a/frontend/src/hooks/useCustomPois.ts +++ b/frontend/src/hooks/useCustomPois.ts @@ -27,8 +27,20 @@ function customPoisKey(parcelCad?: string | null): unknown[] { return ["custom-pois", parcelCad ?? null]; } +// Canonical analyze key prefix is ["parcel-analyze", cad, horizon] (see +// site-finder-api.ts `useParcelAnalyzeQuery`); invalidating with the +// prefix [parcel-analyze, cad] matches every horizon variant. Custom-POI +// add/update/delete also influences the standalone POI score endpoint +// ["parcel-poi-score", cad] (see `useParcelPoiScoreQuery`), so both must +// be invalidated to refresh score + breakdown after a mutation. The +// previous key ["analyze", cad] never matched any live useQuery — bug +// reference: issue #1241. function analyzeKey(parcelCad: string): unknown[] { - return ["analyze", parcelCad]; + return ["parcel-analyze", parcelCad]; +} + +function poiScoreKey(parcelCad: string): unknown[] { + return ["parcel-poi-score", parcelCad]; } // --------------------------------------------------------------------------- @@ -56,7 +68,10 @@ export function useCustomPois(parcelCad?: string | null) { } /** - * Create a custom POI. Invalidates list + analyze query on success. + * Create a custom POI. On success invalidates: + * - ["custom-pois", parcelCad] (scoped list) + ["custom-pois", null] (global) + * - ["parcel-analyze", parcelCad] prefix (matches every horizon variant) + * - ["parcel-poi-score", parcelCad] (POI weighted score) */ export function useAddCustomPoi(parcelCad?: string | null) { const queryClient = useQueryClient(); @@ -75,6 +90,9 @@ export function useAddCustomPoi(parcelCad?: string | null) { void queryClient.invalidateQueries({ queryKey: customPoisKey(null) }); if (parcelCad) { void queryClient.invalidateQueries({ queryKey: analyzeKey(parcelCad) }); + void queryClient.invalidateQueries({ + queryKey: poiScoreKey(parcelCad), + }); } }, }); @@ -99,6 +117,9 @@ export function useUpdateCustomPoi(parcelCad?: string | null) { void queryClient.invalidateQueries({ queryKey: customPoisKey(null) }); if (parcelCad) { void queryClient.invalidateQueries({ queryKey: analyzeKey(parcelCad) }); + void queryClient.invalidateQueries({ + queryKey: poiScoreKey(parcelCad), + }); } }, }); @@ -122,6 +143,9 @@ export function useDeleteCustomPoi(parcelCad?: string | null) { void queryClient.invalidateQueries({ queryKey: customPoisKey(null) }); if (parcelCad) { void queryClient.invalidateQueries({ queryKey: analyzeKey(parcelCad) }); + void queryClient.invalidateQueries({ + queryKey: poiScoreKey(parcelCad), + }); } }, });