@@ -23,9 +23,10 @@ interface MainPageProps {
2323}
2424
2525export interface CreateRunResponse {
26- browserId : string ;
26+ browserId : string | null ;
2727 runId : string ;
2828 robotMetaId : string ;
29+ httpExecution ?: boolean ;
2930}
3031
3132export interface ScheduleRunResponse {
@@ -50,7 +51,7 @@ export const MainPage = ({ handleEditRecording, initialContent }: MainPageProps)
5051 let aborted = false ;
5152
5253 const { notify, setRerenderRuns, setRecordingId } = useGlobalInfoStore ( ) ;
53- const { invalidateRuns, addOptimisticRun } = useCacheInvalidation ( ) ;
54+ const { invalidateRuns, updateOptimisticRun } = useCacheInvalidation ( ) ;
5455 const navigate = useNavigate ( ) ;
5556
5657 React . useEffect ( ( ) => {
@@ -157,19 +158,36 @@ export const MainPage = ({ handleEditRecording, initialContent }: MainPageProps)
157158 isOptimistic : true
158159 } ;
159160
160- addOptimisticRun ( optimisticRun ) ;
161+ updateOptimisticRun ( optimisticRun ) ;
162+ setIds ( { browserId : '' , runId : optimisticRun . runId , robotMetaId : runningRecordingId } ) ;
163+ navigate ( `/runs/${ runningRecordingId } /run/${ optimisticRun . runId } ` ) ;
161164
162165 createAndRunRecording ( runningRecordingId , settings ) . then ( ( response : CreateRunResponseWithQueue ) => {
163166 invalidateRuns ( ) ;
164167 const { browserId, runId, robotMetaId, queued } = response ;
165168
169+ if ( ! runId && ! queued ) {
170+ notify ( 'error' , t ( 'main_page.notifications.run_start_failed' , { name : runningRecordingName } ) ) ;
171+ setContent ( 'robots' ) ;
172+ return ;
173+ }
174+
175+ const realRun = {
176+ ...optimisticRun ,
177+ runId,
178+ status : browserId === null ? 'success' : ( queued ? 'queued' : 'running' ) ,
179+ isOptimistic : true
180+ } ;
181+
182+ updateOptimisticRun ( realRun , optimisticRun . runId ) ;
183+
166184 setIds ( { browserId, runId, robotMetaId } ) ;
167185 navigate ( `/runs/${ robotMetaId } /run/${ runId } ` ) ;
168186
169187 if ( queued ) {
170188 setQueuedRuns ( prev => new Set ( [ ...prev , runId ] ) ) ;
171189 notify ( 'info' , `Run queued: ${ runningRecordingName } ` ) ;
172- } else {
190+ } else if ( browserId ) {
173191 const socket = io ( `${ apiUrl } /${ browserId } ` , {
174192 transports : [ "websocket" , "polling" ] ,
175193 rejectUnauthorized : false
@@ -205,6 +223,8 @@ export const MainPage = ({ handleEditRecording, initialContent }: MainPageProps)
205223 } else {
206224 notify ( 'error' , t ( 'main_page.notifications.run_start_failed' , { name : runningRecordingName } ) ) ;
207225 }
226+ } else if ( runId ) {
227+ notify ( 'info' , t ( 'main_page.notifications.run_started' , { name : runningRecordingName } ) ) ;
208228 }
209229
210230 setContent ( 'runs' ) ;
@@ -218,7 +238,7 @@ export const MainPage = ({ handleEditRecording, initialContent }: MainPageProps)
218238 socket . off ( 'connect_error' ) ;
219239 socket . off ( 'disconnect' ) ;
220240 }
221- } , [ runningRecordingName , sockets , ids , debugMessageHandler , user ?. id , t , notify , setRerenderRuns , setQueuedRuns , navigate , setContent , setIds , invalidateRuns , addOptimisticRun , runningRecordingId ] ) ;
241+ } , [ runningRecordingName , sockets , ids , debugMessageHandler , user ?. id , t , notify , setRerenderRuns , setQueuedRuns , navigate , setContent , setIds , invalidateRuns , updateOptimisticRun , runningRecordingId ] ) ;
222242
223243 useEffect ( ( ) => {
224244 return ( ) => {
0 commit comments