@@ -29,16 +29,7 @@ export function useAgentLogs(
29
29
30
30
const queryClient = useQueryClient ( ) ;
31
31
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 } ) ;
42
33
43
34
const lastQueriedLogId = useRef ( 0 ) ;
44
35
useEffect ( ( ) => {
@@ -58,7 +49,7 @@ export function useAgentLogs(
58
49
} ) ;
59
50
60
51
useEffect ( ( ) => {
61
- if ( agentLifeCycleState !== "starting" || ! query . isFetched ) {
52
+ if ( agentLifeCycleState !== "starting" || ! isFetched ) {
62
53
return ;
63
54
}
64
55
@@ -85,7 +76,7 @@ export function useAgentLogs(
85
76
return ( ) => {
86
77
socket . close ( ) ;
87
78
} ;
88
- } , [ addLogs , agentId , agentLifeCycleState , query . isFetched ] ) ;
79
+ } , [ addLogs , agentId , agentLifeCycleState , isFetched ] ) ;
89
80
90
81
return logs ;
91
82
}
0 commit comments