Skip to content

Commit 7dc96bb

Browse files
committed
fix: update logic for onMessage
1 parent 6711e28 commit 7dc96bb

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

site/src/pages/CreateWorkspacePage/CreateWorkspacePageExperimental.tsx

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const CreateWorkspacePageExperimental: FC = () => {
4848
const navigate = useNavigate();
4949
const [searchParams] = useSearchParams();
5050

51-
const [currentResponse, setCurrentResponse] =
51+
const [latestResponse, setLatestResponse] =
5252
useState<DynamicParametersResponse | null>(null);
5353
const wsResponseId = useRef<number>(-1);
5454
const ws = useRef<WebSocket | null>(null);
@@ -131,22 +131,17 @@ const CreateWorkspacePageExperimental: FC = () => {
131131
},
132132
);
133133

134-
const onMessage = useCallback(
135-
(response: DynamicParametersResponse) => {
136-
setCurrentResponse((prev) => {
137-
if (prev && prev?.id >= response.id) {
138-
return prev;
139-
}
134+
const onMessage = useEffectEvent((response: DynamicParametersResponse) => {
135+
if (latestResponse && latestResponse?.id >= response.id) {
136+
return;
137+
}
140138

141-
if (!initialParamsSentRef.current && response.parameters.length > 0) {
142-
sendInitialParameters([...response.parameters]);
143-
}
139+
if (!initialParamsSentRef.current && response.parameters.length > 0) {
140+
sendInitialParameters([...response.parameters]);
141+
}
144142

145-
return response;
146-
});
147-
},
148-
[sendInitialParameters],
149-
);
143+
setLatestResponse(response);
144+
});
150145

151146
// Initialize the WebSocket connection when there is a valid template version ID
152147
useEffect(() => {
@@ -269,18 +264,18 @@ const CreateWorkspacePageExperimental: FC = () => {
269264
}, [automateWorkspaceCreation, autoCreateReady]);
270265

271266
const sortedParams = useMemo(() => {
272-
if (!currentResponse?.parameters) {
267+
if (!latestResponse?.parameters) {
273268
return [];
274269
}
275-
return [...currentResponse.parameters].sort((a, b) => a.order - b.order);
276-
}, [currentResponse?.parameters]);
270+
return [...latestResponse.parameters].sort((a, b) => a.order - b.order);
271+
}, [latestResponse?.parameters]);
277272

278273
return (
279274
<>
280275
<Helmet>
281276
<title>{pageTitle(title)}</title>
282277
</Helmet>
283-
{!currentResponse ||
278+
{!latestResponse ||
284279
!templateQuery.data ||
285280
isLoadingFormData ||
286281
isLoadingExternalAuth ||
@@ -290,7 +285,7 @@ const CreateWorkspacePageExperimental: FC = () => {
290285
<CreateWorkspacePageViewExperimental
291286
mode={mode}
292287
defaultName={defaultName}
293-
diagnostics={currentResponse?.diagnostics ?? []}
288+
diagnostics={latestResponse?.diagnostics ?? []}
294289
disabledParams={disabledParams}
295290
defaultOwner={defaultOwner}
296291
owner={owner}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy