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

Commite718c3a

Browse files
authored
fix: improve WebSocket error handling in CreateWorkspacePageExperimental (#17647)
Refactor WebSocket error handling to ensure that errors are only setwhen the current socket ref matches the active one. This preventsunnecessary error messages when the WebSocket connection closesunexpectedlyThis solves the problem of showing error messages because of ReactStrict mode rendering the page twice and opening 2 websocketconnections.
1 parenta226a75 commite718c3a

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

‎site/src/pages/CreateWorkspacePage/CreateWorkspacePageExperimental.tsx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,26 +95,27 @@ const CreateWorkspacePageExperimental: FC = () => {
9595

9696
// Initialize the WebSocket connection when there is a valid template version ID
9797
useEffect(()=>{
98-
if(!realizedVersionId){
99-
return;
100-
}
98+
if(!realizedVersionId)return;
10199

102100
constsocket=API.templateVersionDynamicParameters(
103101
owner.id,
104102
realizedVersionId,
105103
{
106104
onMessage,
107105
onError:(error)=>{
108-
setWsError(error);
106+
if(ws.current===socket){
107+
setWsError(error);
108+
}
109109
},
110110
onClose:()=>{
111-
// There is no reason for the websocket to close while a user is on the page
112-
setWsError(
113-
newDetailedError(
114-
"Websocket connection for dynamic parameters unexpectedly closed.",
115-
"Refresh the page to reset the form.",
116-
),
117-
);
111+
if(ws.current===socket){
112+
setWsError(
113+
newDetailedError(
114+
"Websocket connection for dynamic parameters unexpectedly closed.",
115+
"Refresh the page to reset the form.",
116+
),
117+
);
118+
}
118119
},
119120
},
120121
);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp