@@ -237,33 +237,48 @@ export const AppStore = types
237237 select : ! ! taskID && ! ! annotationID ,
238238 } ) ;
239239
240- taskPromise . then ( ( ) => {
241- const annotation = self . LSF ?. currentAnnotation ;
242- const id = annotation ?. pk ?? annotation ?. id ;
240+ // wait for the task to be loaded and LSF to be initialized
241+ yield taskPromise . then ( async ( ) => {
242+ // wait for self.LSF to be initialized
243+ let maxWait = 1000 ;
244+ while ( ! self . LSF ) {
245+ await new Promise ( ( resolve ) => setTimeout ( resolve , 1 ) ) ;
246+ maxWait -= 1 ;
247+ if ( maxWait <= 0 ) {
248+ break ;
249+ }
250+ }
243251
244- self . LSF ?. setLSFTask ( self . taskStore . selected , id ) ;
252+ if ( self . LSF ) {
253+ const annotation = self . LSF ?. currentAnnotation ;
254+ const id = annotation ?. pk ?? annotation ?. id ;
245255
246- if ( isFF ( FF_REGION_VISIBILITY_FROM_URL ) ) {
247- const { annotation : annIDFromUrl , region : regionIDFromUrl } = History . getParams ( ) ;
248- const annotationStore = self . LSF ?. lsf ?. annotationStore ;
256+ self . LSF ?. setLSFTask ( self . taskStore . selected , id ) ;
249257
250- if ( annIDFromUrl && annotationStore ) {
251- const lsfAnnotation = [ ...annotationStore . annotations , ...annotationStore . predictions ] . find ( ( a ) => {
252- return a . pk === annIDFromUrl || a . id === annIDFromUrl ;
253- } ) ;
258+ if ( isFF ( FF_REGION_VISIBILITY_FROM_URL ) ) {
259+ const { annotation : annIDFromUrl , region : regionIDFromUrl } = History . getParams ( ) ;
260+ const annotationStore = self . LSF ?. lsf ?. annotationStore ;
261+
262+ if ( annIDFromUrl && annotationStore ) {
263+ const lsfAnnotation = [ ...annotationStore . annotations , ...annotationStore . predictions ] . find ( ( a ) => {
264+ return a . pk === annIDFromUrl || a . id === annIDFromUrl ;
265+ } ) ;
254266
255- if ( lsfAnnotation ) {
256- const annID = lsfAnnotation . pk ?? lsfAnnotation . id ;
257- self . LSF ?. setLSFTask ( self . taskStore . selected , annID , undefined , lsfAnnotation . type === "prediction" ) ;
267+ if ( lsfAnnotation ) {
268+ const annID = lsfAnnotation . pk ?? lsfAnnotation . id ;
269+ self . LSF ?. setLSFTask ( self . taskStore . selected , annID , undefined , lsfAnnotation . type === "prediction" ) ;
270+ }
271+ }
272+ if ( regionIDFromUrl ) {
273+ const currentAnn = self . LSF ?. currentAnnotation ;
274+ // Focus on the region by hiding all other regions
275+ currentAnn ?. regionStore ?. setRegionVisible ( regionIDFromUrl ) ;
276+ // Select the region so outliner details are visible
277+ currentAnn ?. regionStore ?. selectRegionByID ( regionIDFromUrl ) ;
258278 }
259279 }
260- if ( regionIDFromUrl ) {
261- const currentAnn = self . LSF ?. currentAnnotation ;
262- // Focus on the region by hiding all other regions
263- currentAnn ?. regionStore ?. setRegionVisible ( regionIDFromUrl ) ;
264- // Select the region so outliner details are visible
265- currentAnn ?. regionStore ?. selectRegionByID ( regionIDFromUrl ) ;
266- }
280+ } else {
281+ console . error ( "LSF not initialized properly" ) ;
267282 }
268283
269284 self . setLoadingData ( false ) ;
0 commit comments