Skip to content

Commit 0e2a44c

Browse files
Fix inconsistent autostart data on ws creation (#19581)
* Fix broken autostart data on ws creation * [dashboard] check workspaceclasses are loaded * Remove user from the effect * Revert ordering --------- Co-authored-by: Sven Efftinge <[email protected]>
1 parent 0414803 commit 0e2a44c

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

components/dashboard/src/workspaces/CreateWorkspacePage.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ export function CreateWorkspacePage() {
9292
});
9393
const defaultIde = computedDefaultEditor;
9494
const [selectedIde, setSelectedIde, selectedIdeIsDirty] = useDirtyState<string | undefined>(defaultIde);
95-
const { computedDefaultClass, data: allowedWorkspaceClasses } = useAllowedWorkspaceClassesMemo(selectedProjectID);
95+
const {
96+
computedDefaultClass,
97+
data: allowedWorkspaceClasses,
98+
isLoading: isLoadingWorkspaceClasses,
99+
} = useAllowedWorkspaceClassesMemo(selectedProjectID);
96100
const defaultWorkspaceClass = props.workspaceClass ?? computedDefaultClass;
97101
const { data: orgSettings } = useOrgSettingsQuery();
98102
const [selectedWsClass, setSelectedWsClass, selectedWsClassIsDirty] = useDirtyState(defaultWorkspaceClass);
@@ -316,7 +320,7 @@ export function CreateWorkspacePage() {
316320

317321
// when workspaceContext is available, we look up if options are remembered
318322
useEffect(() => {
319-
if (!workspaceContext.data || !user || !currentOrg) {
323+
if (!workspaceContext.data || !user?.workspaceAutostartOptions || !currentOrg) {
320324
return;
321325
}
322326
const cloneURL = workspaceContext.data.cloneUrl;
@@ -326,7 +330,10 @@ export function CreateWorkspacePage() {
326330
if (nextLoadOption !== "autoStart") {
327331
return;
328332
}
329-
const rememberedOptions = (user?.workspaceAutostartOptions || []).find(
333+
if (isLoadingWorkspaceClasses || allowedWorkspaceClasses.length === 0) {
334+
return;
335+
}
336+
const rememberedOptions = user.workspaceAutostartOptions.find(
330337
(e) => e.cloneUrl === cloneURL && e.organizationId === currentOrg?.id,
331338
);
332339
if (rememberedOptions) {
@@ -362,7 +369,7 @@ export function CreateWorkspacePage() {
362369
setNextLoadOption("allDone");
363370
// we only update the remembered options when the workspaceContext changes
364371
// eslint-disable-next-line react-hooks/exhaustive-deps
365-
}, [workspaceContext.data, nextLoadOption, setNextLoadOption, project]);
372+
}, [workspaceContext.data, nextLoadOption, project, isLoadingWorkspaceClasses, allowedWorkspaceClasses]);
366373

367374
// Need a wrapper here so we call createWorkspace w/o any arguments
368375
const onClickCreate = useCallback(() => createWorkspace(), [createWorkspace]);

0 commit comments

Comments
 (0)