Skip to content

🀯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

πŸ› fix(task): stop flashing empty state during task list refetch (#16748)

Arvin Xu0b320dde672a
diff --git a/src/features/AgentTasks/AgentTaskList/AgentTasksPage.tsx b/src/features/AgentTasks/AgentTaskList/AgentTasksPage.tsx
index ddbce12a343..1d4b0d25b89 100644
--- a/src/features/AgentTasks/AgentTaskList/AgentTasksPage.tsx
+++ b/src/features/AgentTasks/AgentTaskList/AgentTasksPage.tsx
@@ -61,12 +61,20 @@ const AgentTasksPage = memo<AgentTasksPageProps>(({ agentId }) => {
const { allowed: canCreateTask, reason } = usePermission('create_content');
const viewMode = useTaskStore(taskListSelectors.viewMode);
const useFetchTaskList = useTaskStore((s) => s.useFetchTaskList);
- // Keep the SWR handle so a failed list fetch surfaces error + Retry instead of
- // a permanent skeleton (the store only flips `isTaskListInit` on success β€” see
- // LOBE-11181). `data` (undefined until first success) is the settled signal.
- const { data, error, isLoading, mutate } = useFetchTaskList(
+ // Keep the SWR handle only for `error` + `mutate` (the error/Retry state).
+ const { error, isLoading, mutate } = useFetchTaskList(
agentId ? { agentId } : { allAgents: true },
);
+ // Drive the loading/empty boundary off the store's own init flag, NOT SWR's
+ // per-key `data`. On a scope (agent ↔ all) or visibility switch the store
+ // resets `tasks` + `isTaskListInit` together (`scopeChangeResetState`), but
+ // SWR still holds cached `data` for the target key β€” so keying `hasSettled`
+ // off SWR `data` made it `true` while `tasks` was empty and flashed the "no
+ // tasks" empty during the refetch. `isTaskListInit` flips true only on the
+ // current scope's success and resets in lockstep with `tasks`, so the settled
+ // signal never disagrees with the emptiness signal. Still resets to false on a
+ // failed first load, so we surface loading only while there's no error (below).
+ const isTaskListInit = useTaskStore(taskListSelectors.isTaskListInit);
const isEmptyHero = useTaskStore(taskListSelectors.isListEmpty);
const rawViewOptions = useGlobalStore(systemStatusSelectors.taskListViewOptions);
const viewOptions = useMemo(() => normalizeTaskListViewOptions(rawViewOptions), [rawViewOptions]);
@@ -164,9 +172,9 @@ const AgentTasksPage = memo<AgentTasksPageProps>(({ agentId }) => {
>
{!inlineCollapsed && <CreateTaskInlineEntry agentId={agentId} lockAssignee={!!agentId} />}
<TaskList
- data={data}
+ data={isTaskListInit || undefined}
error={error}
- isLoading={isLoading}
+ isLoading={isLoading || (!isTaskListInit && !error)}
options={viewOptions}
routeScope={routeScope}
onRetry={() => mutate()}
diff --git a/src/features/AgentTasks/AgentTaskList/KanbanBoard.tsx b/src/features/AgentTasks/AgentTaskList/KanbanBoard.tsx
index 83b6c489880..9e863691793 100644
--- a/src/features/AgentTasks/AgentTaskList/KanbanBoard.tsx
+++ b/src/features/AgentTasks/AgentTaskList/KanbanBoard.tsx
@@ -88,12 +88,18 @@ const KanbanBoard = memo<KanbanBoardProps>(({ agentId, routeScope }) => {
const { allowed: canEditTask } = usePermission('create_content');
const useFetchTaskGroupList = useTaskStore((s) => s.useFetchTaskGroupList);
- // Surface a failed group fetch as error + Retry instead of a permanent
- // skeleton board (LOBE-11181). `data` (undefined until first success) is the
- // settled signal.
- const { data, error, isLoading, mutate } = useFetchTaskGroupList(
+ // Keep the SWR handle only for `error` + `mutate` (the error/Retry state).
+ const { error, isLoading, mutate } = useFetchTaskGroupList(
agentId ? { agentId } : { allAgents: true },
);
+ // Drive the loading/empty boundary off the store's own init flag, NOT SWR's
+ // per-key `data`. On a scope or visibility switch the store resets
+ // `taskGroups` + `isTaskGroupListInit` together (`scopeChangeResetState`)
+ // while SWR still holds cached `data` for the target key β€” keying `hasSettled`
+ // off SWR `data` flashed the "no tasks" empty board during the refetch.
+ // `isTaskGroupListInit` resets in lockstep with `taskGroups`, so the settled
+ // signal never disagrees with the emptiness signal.
+ const isTaskGroupListInit = useTaskStore(taskListSelectors.isTaskGroupListInit);
const taskGroups = useTaskStore(taskListSelectors.taskGroups);
const updateTaskStatus = useTaskStore((s) => s.updateTaskStatus);
@@ -283,12 +289,12 @@ const KanbanBoard = memo<KanbanBoardProps>(({ agentId, routeScope }) => {
// undefined until the first fetch settles.
return (
<AsyncBoundary
- data={data}
+ data={isTaskGroupListInit || undefined}
empty={emptyState}
error={error}
errorVariant={'block'}
isEmpty={totalTasks === 0}
- isLoading={isLoading}
+ isLoading={isLoading || (!isTaskGroupListInit && !error)}
loading={skeletonBoard}
onRetry={() => mutate()}
>
diff --git a/src/features/AgentTasks/AgentTaskList/TaskList.tsx b/src/features/AgentTasks/AgentTaskList/TaskList.tsx
index a43f66f6b2e..f4da81ab4bd 100644
--- a/src/features/AgentTasks/AgentTaskList/TaskList.tsx
+++ b/src/features/AgentTasks/AgentTaskList/TaskList.tsx
@@ -29,7 +29,12 @@ import {
import TaskItemSkeleton from './TaskItemSkeleton';
interface TaskListProps {
- /** The list SWR result β€” `undefined` until the first fetch settles (the settled signal). */
+ /**
+ * Settled signal β€” truthy once the current scope's list has loaded into the
+ * store, `undefined` while unsettled. Derived from the store's
+ * `isTaskListInit` (not raw SWR `data`) so it resets in lockstep with `tasks`
+ * on a scope/visibility switch and never disagrees with the empty signal.
+ */
data?: unknown;
/** Thrown error from the list SWR β€” surfaced as a failure state, not a skeleton. */
error?: unknown;
@@ -298,8 +303,8 @@ const TaskList = memo<TaskListProps>((props) => {
);
// Error is gated ahead of empty by AsyncBoundary, so a failed fetch shows a
- // Retry block instead of the "no tasks" empty (LOBE-11181). `data` is the SWR
- // result β€” undefined until the first fetch settles.
+ // Retry block instead of the "no tasks" empty (LOBE-11181). `data` is the
+ // store-derived settled signal β€” see the `data` prop doc above.
return (
<AsyncBoundary
data={data}