Skip to content

Commit f74eda4

Browse files
committed
fix: revert log/enabled logic for useAgentLogs
1 parent 6935f50 commit f74eda4

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

site/src/modules/resources/AgentLogs/useAgentLogs.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,7 @@ export function useAgentLogs(
2929

3030
const queryClient = useQueryClient();
3131
const queryOptions = agentLogs(workspaceId, agentId);
32-
const query = useQuery({ ...queryOptions, enabled });
33-
34-
// One pitfall with the current approach: the enabled property does NOT
35-
// prevent the useQuery call above from eventually having data. All it does
36-
// is prevent it from getting data on its own. Let's say a different useQuery
37-
// call elsewhere in the app has the same query key and is enabled. When it
38-
// gets data back from the server, the useQuery call here will re-render with
39-
// that same new data, even though this state is "disabled". This can EASILY
40-
// cause bugs.
41-
const logs = enabled ? query.data : undefined;
32+
const { data: logs, isFetched } = useQuery({ ...queryOptions, enabled });
4233

4334
const lastQueriedLogId = useRef(0);
4435
useEffect(() => {
@@ -58,7 +49,7 @@ export function useAgentLogs(
5849
});
5950

6051
useEffect(() => {
61-
if (agentLifeCycleState !== "starting" || !query.isFetched) {
52+
if (agentLifeCycleState !== "starting" || !isFetched) {
6253
return;
6354
}
6455

@@ -85,7 +76,7 @@ export function useAgentLogs(
8576
return () => {
8677
socket.close();
8778
};
88-
}, [addLogs, agentId, agentLifeCycleState, query.isFetched]);
79+
}, [addLogs, agentId, agentLifeCycleState, isFetched]);
8980

9081
return logs;
9182
}

0 commit comments

Comments
 (0)