@@ -509,7 +509,7 @@ function registerEntryAssets(manifest) {
509509
510510// ---- Asset Tracking ----
511511
512- function createAssetTracking ( ) {
512+ function createAssetTracking ( lowPriorityPreloads ) {
513513 const boundaryModules = new Map ( ) ;
514514 const boundaryStyles = new Map ( ) ;
515515 const emittedAssets = new Set ( ) ;
@@ -521,7 +521,7 @@ function createAssetTracking() {
521521 emittedAssets,
522522 inlineStyles,
523523 preloadLinks : null ,
524- lowModules : null ,
524+ lowModules : lowPriorityPreloads !== false ? new Set ( ) : null ,
525525 // Inline styles (dev CSS collected from the module graph, critical CSS)
526526 // dedupe by `id` — repeated registrations reuse the same entry object so
527527 // boundary Sets and the head injection never emit the same style twice.
@@ -1489,21 +1489,14 @@ function nonceDestination(tag, props) {
14891489 }
14901490}
14911491
1492- // `lowModules` holds module hints outside the entry's static import closure that no
1493- // author wrote: they yield bandwidth to the modules hydration waits on.
1492+ // `lowModules` (null when `lowPriorityPreloads: false`) holds the module hints that
1493+ // keep default priority: the entry's static import closure and authored links. Every
1494+ // other module hint goes low, yielding bandwidth to the modules hydration waits on.
14941495function modulePreloadLink ( url , scriptAttr , lowModules ) {
1495- const priority = lowModules && lowModules . has ( url ) ? ' fetchpriority="low"' : "" ;
1496+ const priority = lowModules && ! lowModules . has ( url ) ? ' fetchpriority="low"' : "" ;
14961497 return `<link rel="modulepreload" href="${ url } "${ priority } ${ scriptAttr } >` ;
14971498}
14981499
1499- // `defaultPriority` marks the entry closure and authored links (see `modulePreloadLink`).
1500- function trackModulePriority ( tracking , type , value , defaultPriority ) {
1501- const low = tracking . lowModules ;
1502- if ( ! low || type !== "module" ) return ;
1503- if ( defaultPriority ) low . delete ( value ) ;
1504- else if ( ! tracking . emittedAssets . has ( value ) ) low . add ( value ) ;
1505- }
1506-
15071500function nonceAttr ( nonce , destination ) {
15081501 if ( ! nonce || ! destination ) return "" ;
15091502 return destination === "script" ? nonce . scriptAttr : nonce . styleAttr ;
@@ -1806,8 +1799,7 @@ export function renderToString(code, options = {}) {
18061799 } ,
18071800 onError : serializerErrorHook ( options . onError )
18081801 } ) ;
1809- const tracking = createAssetTracking ( ) ;
1810- if ( options . lowPriorityPreloads !== false ) tracking . lowModules = new Set ( ) ;
1802+ const tracking = createAssetTracking ( options . lowPriorityPreloads ) ;
18111803 const headRegistry = createHeadRegistry ( ) ;
18121804 // Render-local, never on the context: the finished context lingers as the
18131805 // module global, and another request's writes must not read this latch.
@@ -1856,7 +1848,7 @@ export function renderToString(code, options = {}) {
18561848 }
18571849 styles . add ( value ) ;
18581850 }
1859- trackModulePriority ( tracking , type , value , defaultPriority ) ;
1851+ if ( defaultPriority && tracking . lowModules ) tracking . lowModules . add ( value ) ;
18601852 tracking . emittedAssets . add ( value ) ;
18611853 }
18621854 } ;
@@ -2807,8 +2799,7 @@ export function renderToStream(code, options = {}) {
28072799 tmp += payload ;
28082800 }
28092801 } ;
2810- const tracking = createAssetTracking ( ) ;
2811- if ( options . lowPriorityPreloads !== false ) tracking . lowModules = new Set ( ) ;
2802+ const tracking = createAssetTracking ( options . lowPriorityPreloads ) ;
28122803 const headRegistry = createHeadRegistry ( ) ;
28132804 let headScriptFlushed = false ;
28142805 // Head patch ops park on `_$HY.hp[key]` and apply when the owning
@@ -2890,7 +2881,7 @@ export function renderToStream(code, options = {}) {
28902881 }
28912882 styles . add ( value ) ;
28922883 }
2893- trackModulePriority ( tracking , type , value , defaultPriority ) ;
2884+ if ( defaultPriority && tracking . lowModules ) tracking . lowModules . add ( value ) ;
28942885 if ( ! tracking . emittedAssets . has ( value ) ) {
28952886 tracking . emittedAssets . add ( value ) ;
28962887 if ( firstFlushed ) sink . asset ( type , value ) ;
0 commit comments