@@ -50,7 +50,7 @@ export const MainPage = ({ handleEditRecording, initialContent }: MainPageProps)
50
50
let aborted = false ;
51
51
52
52
const { notify, setRerenderRuns, setRecordingId } = useGlobalInfoStore ( ) ;
53
- const { invalidateRuns } = useCacheInvalidation ( ) ;
53
+ const { invalidateRuns, addOptimisticRun } = useCacheInvalidation ( ) ;
54
54
const navigate = useNavigate ( ) ;
55
55
56
56
const { state } = useContext ( AuthContext ) ;
@@ -132,19 +132,34 @@ export const MainPage = ({ handleEditRecording, initialContent }: MainPageProps)
132
132
setRerenderRuns ( true ) ;
133
133
invalidateRuns ( ) ;
134
134
} )
135
- } , [ runningRecordingName , aborted , currentInterpretationLog , notify , setRerenderRuns , invalidateRuns ] ) ;
135
+ } , [ runningRecordingName , aborted , currentInterpretationLog , notify , setRerenderRuns ] ) ;
136
136
137
137
const debugMessageHandler = useCallback ( ( msg : string ) => {
138
138
setCurrentInterpretationLog ( ( prevState ) =>
139
139
prevState + '\n' + `[${ new Date ( ) . toLocaleString ( ) } ] ` + msg ) ;
140
140
} , [ currentInterpretationLog ] )
141
141
142
142
const handleRunRecording = useCallback ( ( settings : RunSettings ) => {
143
+ // Add optimistic run to cache immediately
144
+ const optimisticRun = {
145
+ id : runningRecordingId ,
146
+ runId : `temp-${ Date . now ( ) } ` , // Temporary ID until we get the real one
147
+ status : 'running' ,
148
+ name : runningRecordingName ,
149
+ startedAt : new Date ( ) . toISOString ( ) ,
150
+ finishedAt : '' ,
151
+ robotMetaId : runningRecordingId ,
152
+ log : 'Starting...' ,
153
+ isOptimistic : true
154
+ } ;
155
+
156
+ addOptimisticRun ( optimisticRun ) ;
157
+
143
158
createAndRunRecording ( runningRecordingId , settings ) . then ( ( response : CreateRunResponseWithQueue ) => {
159
+ invalidateRuns ( ) ;
144
160
const { browserId, runId, robotMetaId, queued } = response ;
145
161
146
162
setIds ( { browserId, runId, robotMetaId } ) ;
147
- invalidateRuns ( ) ;
148
163
navigate ( `/runs/${ robotMetaId } /run/${ runId } ` ) ;
149
164
150
165
if ( queued ) {
@@ -160,8 +175,6 @@ export const MainPage = ({ handleEditRecording, initialContent }: MainPageProps)
160
175
161
176
socket . on ( 'debugMessage' , debugMessageHandler ) ;
162
177
socket . on ( 'run-completed' , ( data ) => {
163
- setRunningRecordingName ( '' ) ;
164
- setCurrentInterpretationLog ( '' ) ;
165
178
setRerenderRuns ( true ) ;
166
179
invalidateRuns ( ) ;
167
180
@@ -201,7 +214,13 @@ export const MainPage = ({ handleEditRecording, initialContent }: MainPageProps)
201
214
socket . off ( 'connect_error' ) ;
202
215
socket . off ( 'disconnect' ) ;
203
216
}
204
- } , [ runningRecordingName , sockets , ids , debugMessageHandler , user ?. id , t , notify , setRerenderRuns , setQueuedRuns , navigate , setContent , setIds , invalidateRuns ] ) ;
217
+ } , [ runningRecordingName , sockets , ids , debugMessageHandler , user ?. id , t , notify , setRerenderRuns , setQueuedRuns , navigate , setContent , setIds , invalidateRuns , addOptimisticRun , runningRecordingId ] ) ;
218
+
219
+ useEffect ( ( ) => {
220
+ return ( ) => {
221
+ queuedRuns . clear ( ) ;
222
+ } ;
223
+ } , [ ] ) ;
205
224
206
225
const handleScheduleRecording = async ( settings : ScheduleSettings ) => {
207
226
const { message, runId } : ScheduleRunResponse = await scheduleStoredRecording ( runningRecordingId , settings ) ;
@@ -225,7 +244,7 @@ export const MainPage = ({ handleEditRecording, initialContent }: MainPageProps)
225
244
226
245
const handleRunCompleted = ( completionData : any ) => {
227
246
setRerenderRuns ( true ) ;
228
- invalidateRuns ( ) ;
247
+ invalidateRuns ( ) ; // Invalidate cache to show completed run status
229
248
230
249
if ( queuedRuns . has ( completionData . runId ) ) {
231
250
setQueuedRuns ( prev => {
0 commit comments