Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit089f960

Browse files
fix(site): only attempt to watch containers when agent connected (#18873)
This PR ensures we do not attempt to call `containers/watch` on theagent _before_ it is connected.
1 parent4354633 commit089f960

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

‎site/src/modules/resources/useAgentContainers.test.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,22 @@ describe("useAgentContainers", () => {
193193
displayErrorSpy.mockRestore();
194194
watchAgentContainersSpy.mockRestore();
195195
});
196+
197+
it("does not establish WebSocket connection when agent is not connected",()=>{
198+
constwatchAgentContainersSpy=jest.spyOn(API,"watchAgentContainers");
199+
200+
constdisconnectedAgent={
201+
...MockWorkspaceAgent,
202+
status:"disconnected"asconst,
203+
};
204+
205+
const{ result}=renderHook(()=>useAgentContainers(disconnectedAgent),{
206+
wrapper:createWrapper(),
207+
});
208+
209+
expect(watchAgentContainersSpy).not.toHaveBeenCalled();
210+
expect(result.current).toBeUndefined();
211+
212+
watchAgentContainersSpy.mockRestore();
213+
});
196214
});

‎site/src/modules/resources/useAgentContainers.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ export function useAgentContainers(
3131
);
3232

3333
useEffect(()=>{
34+
if(agent.status!=="connected"){
35+
return;
36+
}
37+
3438
constsocket=watchAgentContainers(agent.id);
3539

3640
socket.addEventListener("message",(event)=>{
@@ -53,7 +57,7 @@ export function useAgentContainers(
5357
});
5458

5559
return()=>socket.close();
56-
},[agent.id,updateDevcontainersCache]);
60+
},[agent.id,agent.status,updateDevcontainersCache]);
5761

5862
returndevcontainers;
5963
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp