diff --git a/components/dashboard/src/workspaces/CreateWorkspacePage.tsx b/components/dashboard/src/workspaces/CreateWorkspacePage.tsx index e406a4be5b8535..504c0b1e8fc496 100644 --- a/components/dashboard/src/workspaces/CreateWorkspacePage.tsx +++ b/components/dashboard/src/workspaces/CreateWorkspacePage.tsx @@ -92,7 +92,11 @@ export function CreateWorkspacePage() { }); const defaultIde = computedDefaultEditor; const [selectedIde, setSelectedIde, selectedIdeIsDirty] = useDirtyState(defaultIde); - const { computedDefaultClass, data: allowedWorkspaceClasses } = useAllowedWorkspaceClassesMemo(selectedProjectID); + const { + computedDefaultClass, + data: allowedWorkspaceClasses, + isLoading: isLoadingWorkspaceClasses, + } = useAllowedWorkspaceClassesMemo(selectedProjectID); const defaultWorkspaceClass = props.workspaceClass ?? computedDefaultClass; const { data: orgSettings } = useOrgSettingsQuery(); const [selectedWsClass, setSelectedWsClass, selectedWsClassIsDirty] = useDirtyState(defaultWorkspaceClass); @@ -316,7 +320,7 @@ export function CreateWorkspacePage() { // when workspaceContext is available, we look up if options are remembered useEffect(() => { - if (!workspaceContext.data || !user || !currentOrg) { + if (!workspaceContext.data || !user?.workspaceAutostartOptions || !currentOrg) { return; } const cloneURL = workspaceContext.data.cloneUrl; @@ -326,7 +330,10 @@ export function CreateWorkspacePage() { if (nextLoadOption !== "autoStart") { return; } - const rememberedOptions = (user?.workspaceAutostartOptions || []).find( + if (isLoadingWorkspaceClasses || allowedWorkspaceClasses.length === 0) { + return; + } + const rememberedOptions = user.workspaceAutostartOptions.find( (e) => e.cloneUrl === cloneURL && e.organizationId === currentOrg?.id, ); if (rememberedOptions) { @@ -362,7 +369,7 @@ export function CreateWorkspacePage() { setNextLoadOption("allDone"); // we only update the remembered options when the workspaceContext changes // eslint-disable-next-line react-hooks/exhaustive-deps - }, [workspaceContext.data, nextLoadOption, setNextLoadOption, project]); + }, [workspaceContext.data, nextLoadOption, project, isLoadingWorkspaceClasses, allowedWorkspaceClasses]); // Need a wrapper here so we call createWorkspace w/o any arguments const onClickCreate = useCallback(() => createWorkspace(), [createWorkspace]);