@@ -483,30 +483,40 @@ export class MultiFileDiffViewerState {
483483 return false ;
484484 }
485485 try {
486+ // Show progress bar
486487 this . loadingState . start ( ) ;
487488 await tick ( ) ;
488489 await animationFramePromise ( ) ;
489490
491+ // Update metadata
490492 this . diffMetadata = await meta ( ) ;
491493 await tick ( ) ;
492494 await animationFramePromise ( ) ;
493495
496+ // Clear previous state
494497 this . clear ( false ) ;
495498 await tick ( ) ;
496499 await animationFramePromise ( ) ;
497500
501+ // Setup generator
498502 const generator = await patches ( ) ;
503+ await tick ( ) ;
504+ await animationFramePromise ( ) ;
499505
506+ // Load patches
500507 const tempDetails : FileDetails [ ] = [ ] ;
508+ let lastYield = Date . now ( ) ;
501509 for await ( const details of generator ) {
502510 this . loadingState . loadedCount ++ ;
503511
504512 // Pushing directly to the main array causes too many signals to update (lag)
505513 tempDetails . push ( details ) ;
506514
507- // TODO this makes it load one patch per frame
508- await tick ( ) ;
509- await animationFramePromise ( ) ;
515+ if ( Date . now ( ) - lastYield > 50 ) {
516+ await tick ( ) ;
517+ await animationFramePromise ( ) ;
518+ lastYield = Date . now ( ) ;
519+ }
510520 }
511521 if ( tempDetails . length === 0 ) {
512522 throw new Error ( "No valid patches found in the provided data." ) ;
@@ -520,6 +530,10 @@ export class MultiFileDiffViewerState {
520530 alert ( "Failed to load patches: " + e ) ;
521531 return false ;
522532 } finally {
533+ // Let the last progress update render before closing the loading state
534+ await tick ( ) ;
535+ await animationFramePromise ( ) ;
536+
523537 this . loadingState . done ( ) ;
524538 }
525539 }
0 commit comments