Skip to content

Commit 005ecee

Browse files
committed
fix(tasks): fix sidebar tasks skeleton hanging indefinitely
Switch useTasks to skipToken + keepPreviousData and derive tasksLoading from isLoading (isPending && isFetching) instead of data presence. This matches the established useWorkflows pattern and prevents the skeleton from hanging forever on query errors or when workspaceId is temporarily absent.
1 parent 49c1201 commit 005ecee

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

apps/sim/app/workspace/[workspaceId]/w/components/sidebar/sidebar.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -790,8 +790,7 @@ export const Sidebar = memo(function Sidebar() {
790790
)
791791
}
792792

793-
const { data: fetchedTasks } = useTasks(workspaceId)
794-
const tasksLoading = fetchedTasks === undefined
793+
const { data: fetchedTasks, isLoading: tasksLoading } = useTasks(workspaceId)
795794

796795
useTaskEvents(workspaceId)
797796

apps/sim/hooks/queries/tasks.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
1+
import {
2+
keepPreviousData,
3+
skipToken,
4+
useMutation,
5+
useQuery,
6+
useQueryClient,
7+
} from '@tanstack/react-query'
28
import { requestJson } from '@/lib/api/client/request'
39
import {
410
addMothershipChatResourceContract,
@@ -210,8 +216,8 @@ export async function fetchTasks(
210216
export function useTasks(workspaceId?: string) {
211217
return useQuery({
212218
queryKey: taskKeys.list(workspaceId),
213-
queryFn: ({ signal }) => fetchTasks(workspaceId as string, signal),
214-
enabled: Boolean(workspaceId),
219+
queryFn: workspaceId ? ({ signal }) => fetchTasks(workspaceId, signal) : skipToken,
220+
placeholderData: keepPreviousData,
215221
staleTime: 60 * 1000,
216222
})
217223
}

0 commit comments

Comments
 (0)