@@ -52,6 +52,7 @@ const preloadStr = 'preload';
5252
5353let highCount = 0 ;
5454let lowCount = 0 ;
55+ const max = 11 ;
5556/**
5657 * This is called when a bundle is queued or finished loading.
5758 *
@@ -61,11 +62,11 @@ let lowCount = 0;
6162 * We make sure to first empty the high priority items, first-in-last-out.
6263 */
6364const trigger = ( ) => {
64- while ( highCount < 6 && high . length ) {
65+ while ( highCount < max && high . length ) {
6566 const bundle = high . pop ( ) ! ;
6667 preloadOne ( bundle ! , true ) ;
6768 }
68- while ( highCount + lowCount < 6 && low . length ) {
69+ while ( highCount + lowCount < max && low . length ) {
6970 const bundle = low . pop ( ) ! ;
7071 preloadOne ( bundle ! ) ;
7172 }
@@ -108,8 +109,13 @@ const preloadOne = (bundle: BundleImport, priority?: boolean) => {
108109
109110 bundle . $state$ = BundleImportState . Loading ;
110111 /** Now that we processed the bundle, its dependencies are needed ASAP */
111- preload ( bundle . $dynamicImports$ ) ;
112- preload ( bundle . $imports$ , priority ) ;
112+ if ( priority ) {
113+ // make sure to queue the high priority imports first so they preloaded before the low priority ones
114+ preload ( bundle . $imports$ , priority ) ;
115+ preload ( bundle . $dynamicImports$ ) ;
116+ } else {
117+ preload ( [ ...bundle . $imports$ , ...bundle . $dynamicImports$ ] ) ;
118+ }
113119} ;
114120
115121const makeBundle = ( path : string , imports : string [ ] , dynamicImports : string [ ] ) => {
@@ -165,8 +171,7 @@ const parseBundleGraph = (text: string, base: string) => {
165171 for ( const name of toProcess ) {
166172 const bundle = bundles . get ( name ) ! ;
167173 // we assume low priority
168- preload ( bundle . $dynamicImports$ ) ;
169- preload ( bundle . $imports$ ) ;
174+ preload ( [ ...bundle . $imports$ , ...bundle . $dynamicImports$ ] ) ;
170175 }
171176} ;
172177
0 commit comments