fix: remove stale React Query cache on site inspection complete
SSE complete event now removes the cached siteInspection query data so the result page fetches fresh data with aggregate_scores from API. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
|
||||
import { useEffect, useRef } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
import { useSiteInspectionStore } from "@/stores/useSiteInspectionStore";
|
||||
import { api } from "@/lib/api";
|
||||
import type {
|
||||
@ -29,6 +30,7 @@ export function useSiteInspectionSSE(siteInspectionId: string | null) {
|
||||
setError,
|
||||
} = useSiteInspectionStore();
|
||||
const router = useRouter();
|
||||
const queryClient = useQueryClient();
|
||||
const eventSourceRef = useRef<EventSource | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
@ -94,7 +96,10 @@ export function useSiteInspectionSSE(siteInspectionId: string | null) {
|
||||
const data: SSESiteComplete = JSON.parse(e.data);
|
||||
setCompleted(data.aggregate_scores);
|
||||
eventSource.close();
|
||||
// 결과 페이지로 자동 이동
|
||||
// stale 캐시 제거 → 결과 페이지에서 fresh 데이터 로드
|
||||
queryClient.removeQueries({
|
||||
queryKey: ["siteInspection", siteInspectionId],
|
||||
});
|
||||
router.push(`/site-inspections/${siteInspectionId}`);
|
||||
} catch {
|
||||
// JSON 파싱 실패 무시
|
||||
@ -138,5 +143,6 @@ export function useSiteInspectionSSE(siteInspectionId: string | null) {
|
||||
setCompleted,
|
||||
setError,
|
||||
router,
|
||||
queryClient,
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user