Skip to content

Commit a1400ca

Browse files
authored
fix(logs): replace initialData with placeholderData to fix stale log details (#3279)
1 parent 2fc2e12 commit a1400ca

File tree

2 files changed

+5
-19
lines changed

2 files changed

+5
-19
lines changed

apps/sim/app/workspace/[workspaceId]/logs/logs.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,10 @@ export default function Logs() {
208208

209209
const selectedLog = useMemo(() => {
210210
if (!selectedLogFromList) return null
211-
if (!activeLogQuery.data || isPreviewOpen) return selectedLogFromList
211+
if (!activeLogQuery.data || isPreviewOpen || activeLogQuery.isPlaceholderData)
212+
return selectedLogFromList
212213
return { ...selectedLogFromList, ...activeLogQuery.data }
213-
}, [selectedLogFromList, activeLogQuery.data, isPreviewOpen])
214+
}, [selectedLogFromList, activeLogQuery.data, activeLogQuery.isPlaceholderData, isPreviewOpen])
214215

215216
const handleLogHover = useCallback(
216217
(log: WorkflowLog) => {
@@ -650,7 +651,7 @@ export default function Logs() {
650651
hasActiveFilters={filtersActive}
651652
/>
652653

653-
{isPreviewOpen && activeLogQuery.data?.executionId && (
654+
{isPreviewOpen && !activeLogQuery.isPlaceholderData && activeLogQuery.data?.executionId && (
654655
<ExecutionSnapshot
655656
executionId={activeLogQuery.data.executionId}
656657
traceSpans={activeLogQuery.data.executionData?.traceSpans}

apps/sim/hooks/queries/logs.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
type QueryClient,
44
useInfiniteQuery,
55
useQuery,
6-
useQueryClient,
76
} from '@tanstack/react-query'
87
import { getEndDateFromTimeRange, getStartDateFromTimeRange } from '@/lib/logs/filters'
98
import { parseQuery, queryToApiParams } from '@/lib/logs/query-parser'
@@ -159,27 +158,13 @@ interface UseLogDetailOptions {
159158
}
160159

161160
export function useLogDetail(logId: string | undefined, options?: UseLogDetailOptions) {
162-
const queryClient = useQueryClient()
163161
return useQuery({
164162
queryKey: logKeys.detail(logId),
165163
queryFn: () => fetchLogDetail(logId as string),
166164
enabled: Boolean(logId) && (options?.enabled ?? true),
167165
refetchInterval: options?.refetchInterval ?? false,
168166
staleTime: 30 * 1000,
169-
initialData: () => {
170-
if (!logId) return undefined
171-
const listQueries = queryClient.getQueriesData<{
172-
pages: { logs: WorkflowLog[] }[]
173-
}>({
174-
queryKey: logKeys.lists(),
175-
})
176-
for (const [, data] of listQueries) {
177-
const match = data?.pages?.flatMap((p) => p.logs).find((l) => l.id === logId)
178-
if (match) return match
179-
}
180-
return undefined
181-
},
182-
initialDataUpdatedAt: 0,
167+
placeholderData: keepPreviousData,
183168
})
184169
}
185170

0 commit comments

Comments
 (0)