@@ -68,6 +68,7 @@ import { Flag } from "@/flag/flag"
6868import { LANGUAGE_EXTENSIONS } from "@/lsp/language"
6969import parsers from "../../../../../../parsers-config.ts"
7070import * as Clipboard from "../../util/clipboard"
71+ import { errorMessage } from "@/util/error"
7172import { Toast , useToast } from "../../ui/toast"
7273import { useKV } from "../../context/kv.tsx"
7374import * as Editor from "../../util/editor"
@@ -180,31 +181,43 @@ export function Session() {
180181 const toast = useToast ( )
181182 const sdk = useSDK ( )
182183
183- createEffect ( async ( ) => {
184- const previousWorkspace = project . workspace . current ( )
185- const result = await sdk . client . session . get ( { sessionID : route . sessionID } , { throwOnError : true } )
186- if ( ! result . data ) {
184+ createEffect ( ( ) => {
185+ const sessionID = route . sessionID
186+ void ( async ( ) => {
187+ const previousWorkspace = project . workspace . current ( )
188+ const result = await sdk . client . session . get ( { sessionID } , { throwOnError : true } )
189+ if ( ! result . data ) {
190+ toast . show ( {
191+ message : `Session not found: ${ sessionID } ` ,
192+ variant : "error" ,
193+ duration : 5000 ,
194+ } )
195+ navigate ( { type : "home" } )
196+ return
197+ }
198+
199+ if ( result . data . workspaceID !== previousWorkspace ) {
200+ project . workspace . set ( result . data . workspaceID )
201+
202+ // Sync all the data for this workspace. Note that this
203+ // workspace may not exist anymore which is why this is not
204+ // fatal. If it doesn't we still want to show the session
205+ // (which will be non-interactive)
206+ try {
207+ await sync . bootstrap ( { fatal : false } )
208+ } catch { }
209+ }
210+ await sync . session . sync ( sessionID )
211+ if ( route . sessionID === sessionID && scroll ) scroll . scrollBy ( 100_000 )
212+ } ) ( ) . catch ( ( error ) => {
213+ if ( route . sessionID !== sessionID ) return
187214 toast . show ( {
188- message : `Session not found: ${ route . sessionID } ` ,
215+ message : errorMessage ( error ) ,
189216 variant : "error" ,
217+ duration : 5000 ,
190218 } )
191219 navigate ( { type : "home" } )
192- return
193- }
194-
195- if ( result . data . workspaceID !== previousWorkspace ) {
196- project . workspace . set ( result . data . workspaceID )
197-
198- // Sync all the data for this workspace. Note that this
199- // workspace may not exist anymore which is why this is not
200- // fatal. If it doesn't we still want to show the session
201- // (which will be non-interactive)
202- try {
203- await sync . bootstrap ( { fatal : false } )
204- } catch ( e ) { }
205- }
206- await sync . session . sync ( route . sessionID )
207- if ( scroll ) scroll . scrollBy ( 100_000 )
220+ } )
208221 } )
209222
210223 let lastSwitch : string | undefined = undefined
0 commit comments