Skip to content

Commit 00fdae6

Browse files
chore: broadcast updates in more places, add staleTime: Infinity
1 parent 2de01f5 commit 00fdae6

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

agent/agentcontainers/api.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,16 @@ func (api *API) Routes() http.Handler {
549549
return r
550550
}
551551

552+
func (api *API) broadcastUpdatesLocked() {
553+
// Broadcast state changes to WebSocket listeners.
554+
for _, ch := range api.updateChans {
555+
select {
556+
case ch <- struct{}{}:
557+
default:
558+
}
559+
}
560+
}
561+
552562
func (api *API) watchContainers(rw http.ResponseWriter, r *http.Request) {
553563
ctx := r.Context()
554564

@@ -676,13 +686,7 @@ func (api *API) updateContainers(ctx context.Context) error {
676686
})
677687

678688
if !statesAreEqual {
679-
// Broadcast state changes to WebSocket listeners.
680-
for _, ch := range api.updateChans {
681-
select {
682-
case ch <- struct{}{}:
683-
default:
684-
}
685-
}
689+
api.broadcastUpdatesLocked()
686690
}
687691
}
688692

@@ -1056,6 +1060,8 @@ func (api *API) handleDevcontainerRecreate(w http.ResponseWriter, r *http.Reques
10561060
dc.Container = nil
10571061
dc.Error = ""
10581062
api.knownDevcontainers[dc.WorkspaceFolder] = dc
1063+
api.broadcastUpdatesLocked()
1064+
10591065
go func() {
10601066
_ = api.CreateDevcontainer(dc.WorkspaceFolder, dc.ConfigPath, WithRemoveExistingContainer())
10611067
}()
@@ -1171,6 +1177,7 @@ func (api *API) CreateDevcontainer(workspaceFolder, configPath string, opts ...D
11711177
dc.Error = ""
11721178
api.recreateSuccessTimes[dc.WorkspaceFolder] = api.clock.Now("agentcontainers", "recreate", "successTimes")
11731179
api.knownDevcontainers[dc.WorkspaceFolder] = dc
1180+
api.broadcastUpdatesLocked()
11741181
api.mu.Unlock()
11751182

11761183
// Ensure an immediate refresh to accurately reflect the

site/src/modules/resources/AgentDevcontainerCard.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,6 @@ export const AgentDevcontainerCard: FC<AgentDevcontainerCardProps> = ({
130130

131131
return { previousData };
132132
},
133-
onSuccess: async () => {
134-
// Invalidate the containers query to refetch updated data.
135-
await queryClient.invalidateQueries({
136-
queryKey: ["agents", parentAgent.id, "containers"],
137-
});
138-
},
139133
onError: (error, _, context) => {
140134
// If the mutation fails, use the context returned from
141135
// onMutate to roll back.

site/src/modules/resources/useAgentContainers.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export function useAgentContainers(
1919
queryFn: () => API.getAgentContainers(agent.id),
2020
enabled: agent.status === "connected",
2121
select: (res) => res.devcontainers,
22+
staleTime: Infinity,
2223
});
2324

2425
const updateDevcontainersCache = useEffectEvent(

0 commit comments

Comments
 (0)