@@ -41,12 +41,10 @@ const CreateWorkspacePage: FC = () => {
41
41
const [ searchParams , setSearchParams ] = useSearchParams ( ) ;
42
42
const { experiments } = useDashboard ( ) ;
43
43
44
- const mode = getWorkspaceMode ( searchParams ) ;
45
44
const customVersionId = searchParams . get ( "version" ) ?? undefined ;
46
45
const defaultName = searchParams . get ( "name" ) ;
47
46
const disabledParams = searchParams . get ( "disable_params" ) ?. split ( "," ) ;
48
- // `?mode=auto` is set, but a prerequisite was not met, and so has been disabled.
49
- const [ isAutoCreateTainted , setIsAutoCreateTainted ] = useState ( false ) ;
47
+ const [ mode , setMode ] = useState ( ( ) => getWorkspaceMode ( searchParams ) ) ;
50
48
51
49
const queryClient = useQueryClient ( ) ;
52
50
const autoCreateWorkspaceMutation = useMutation (
@@ -136,16 +134,25 @@ const CreateWorkspacePage: FC = () => {
136
134
externalAuth ?. every ( ( auth ) => auth . optional || auth . authenticated ) ,
137
135
) ;
138
136
139
- if ( ! isLoadingExternalAuth && ! hasAllRequiredExternalAuth ) {
137
+ let autoStartReady =
138
+ mode === "auto" &&
139
+ ( ! autofillEnabled || userParametersQuery . isSuccess ) &&
140
+ hasAllRequiredExternalAuth ;
141
+
142
+ // `mode=auto` was set, but a prequisite has failed, and so auto-mode should be abandoned.
143
+ if (
144
+ mode === "auto" &&
145
+ ! isLoadingExternalAuth &&
146
+ ! hasAllRequiredExternalAuth
147
+ ) {
140
148
// Prevent suddenly resuming auto-mode if the user connects to all of the required
141
149
// external auth providers.
142
- setIsAutoCreateTainted ( true ) ;
150
+ setMode ( "form" ) ;
151
+ // Ensure this is always false, so that we don't ever let `automateWorkspaceCreation`
152
+ // fire when we're trying to disable it.
153
+ autoStartReady = false ;
143
154
}
144
- const autoStartReady =
145
- mode === "auto" &&
146
- ( ! autofillEnabled || userParametersQuery . isSuccess ) &&
147
- hasAllRequiredExternalAuth &&
148
- ! isAutoCreateTainted ;
155
+
149
156
useEffect ( ( ) => {
150
157
if ( autoStartReady ) {
151
158
void automateWorkspaceCreation ( ) ;
0 commit comments