@@ -52,6 +52,7 @@ import getRamBundleInfo from './DeltaBundler/Serializers/getRamBundleInfo';
5252import { sourceMapStringNonBlocking } from './DeltaBundler/Serializers/sourceMapString' ;
5353import IncrementalBundler from './IncrementalBundler' ;
5454import ResourceNotFoundError from './IncrementalBundler/ResourceNotFoundError' ;
55+ import { calculateBundleProgressRatio } from './lib/bundleProgressUtils' ;
5556import bundleToString from './lib/bundleToString' ;
5657import formatBundlingError from './lib/formatBundlingError' ;
5758import getGraphId from './lib/getGraphId' ;
@@ -857,25 +858,23 @@ export default class Server {
857858 const mres = MultipartResponse . wrapIfSupported ( req , res ) ;
858859
859860 let onProgress = null ;
860- let lastProgress = - 1 ;
861+ let lastRatio = - 1 ;
861862 if ( this . _config . reporter ) {
862863 onProgress = ( transformedFileCount : number , totalFileCount : number ) => {
863- const currentProgress = parseInt (
864- ( transformedFileCount / totalFileCount ) * 100 ,
865- 10 ,
864+ const newRatio = calculateBundleProgressRatio (
865+ transformedFileCount ,
866+ totalFileCount ,
867+ lastRatio ,
866868 ) ;
867869
868- // We want to throttle the updates so that we only show meaningful
869- // UI updates slow enough for the client to actually handle them. For
870- // that, we check the percentage, and only send percentages that are
871- // actually different and that have increased from the last one we sent.
872- if ( currentProgress > lastProgress || totalFileCount < 10 ) {
870+ if ( newRatio > lastRatio ) {
873871 if ( mres instanceof MultipartResponse ) {
874872 mres . writeChunk (
875873 { 'Content-Type' : 'application/json' } ,
876874 JSON . stringify ( {
877875 done : transformedFileCount ,
878876 total : totalFileCount ,
877+ percent : Math . floor ( newRatio * 100 ) ,
879878 } ) ,
880879 ) ;
881880 }
@@ -891,7 +890,7 @@ export default class Server {
891890 res . socket . uncork ( ) ;
892891 }
893892
894- lastProgress = currentProgress ;
893+ lastRatio = newRatio ;
895894 }
896895
897896 this . _reporter . update ( {
0 commit comments