@@ -17,7 +17,7 @@ if (process.env.NODE_ENV !== "production") {
17
17
var React = require ( "next/dist/compiled/react-experimental" ) ;
18
18
var ReactDOM = require ( 'react-dom' ) ;
19
19
20
- var ReactVersion = '18.3.0-experimental-cb3404a0c-20230807 ' ;
20
+ var ReactVersion = '18.3.0-experimental-1a001dac6-20230812 ' ;
21
21
22
22
var ReactSharedInternals = React . __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED ;
23
23
@@ -3693,6 +3693,75 @@ function pushStyleContents(target, props) {
3693
3693
return ;
3694
3694
}
3695
3695
3696
+ function getImagePreloadKey ( href , imageSrcSet , imageSizes ) {
3697
+ var uniquePart = '' ;
3698
+
3699
+ if ( typeof imageSrcSet === 'string' && imageSrcSet !== '' ) {
3700
+ uniquePart += '[' + imageSrcSet + ']' ;
3701
+
3702
+ if ( typeof imageSizes === 'string' ) {
3703
+ uniquePart += '[' + imageSizes + ']' ;
3704
+ }
3705
+ } else {
3706
+ uniquePart += '[][]' + href ;
3707
+ }
3708
+
3709
+ return getResourceKey ( 'image' , uniquePart ) ;
3710
+ }
3711
+
3712
+ function pushImg ( target , props , resources ) {
3713
+ var src = props . src ,
3714
+ srcSet = props . srcSet ;
3715
+
3716
+ if ( props . loading !== 'lazy' && ( typeof src === 'string' || typeof srcSet === 'string' ) && props . fetchPriority !== 'low' && // We exclude data URIs in src and srcSet since these should not be preloaded
3717
+ ! ( typeof src === 'string' && src [ 4 ] === ':' && ( src [ 0 ] === 'd' || src [ 0 ] === 'D' ) && ( src [ 1 ] === 'a' || src [ 1 ] === 'A' ) && ( src [ 2 ] === 't' || src [ 2 ] === 'T' ) && ( src [ 3 ] === 'a' || src [ 3 ] === 'A' ) ) && ! ( typeof srcSet === 'string' && srcSet [ 4 ] === ':' && ( srcSet [ 0 ] === 'd' || srcSet [ 0 ] === 'D' ) && ( srcSet [ 1 ] === 'a' || srcSet [ 1 ] === 'A' ) && ( srcSet [ 2 ] === 't' || srcSet [ 2 ] === 'T' ) && ( srcSet [ 3 ] === 'a' || srcSet [ 3 ] === 'A' ) ) ) {
3718
+ // We have a suspensey image and ought to preload it to optimize the loading of display blocking
3719
+ // resources.
3720
+ var sizes = props . sizes ;
3721
+ var key = getImagePreloadKey ( src , srcSet , sizes ) ;
3722
+ var resource = resources . preloadsMap . get ( key ) ;
3723
+
3724
+ if ( ! resource ) {
3725
+ resource = {
3726
+ type : 'preload' ,
3727
+ chunks : [ ] ,
3728
+ state : NoState ,
3729
+ props : {
3730
+ rel : 'preload' ,
3731
+ as : 'image' ,
3732
+ // There is a bug in Safari where imageSrcSet is not respected on preload links
3733
+ // so we omit the href here if we have imageSrcSet b/c safari will load the wrong image.
3734
+ // This harms older browers that do not support imageSrcSet by making their preloads not work
3735
+ // but this population is shrinking fast and is already small so we accept this tradeoff.
3736
+ href : srcSet ? undefined : src ,
3737
+ imageSrcSet : srcSet ,
3738
+ imageSizes : sizes ,
3739
+ crossOrigin : props . crossOrigin ,
3740
+ integrity : props . integrity ,
3741
+ type : props . type ,
3742
+ fetchPriority : props . fetchPriority ,
3743
+ referrerPolicy : props . referrerPolicy
3744
+ }
3745
+ } ;
3746
+ resources . preloadsMap . set ( key , resource ) ;
3747
+
3748
+ {
3749
+ markAsRenderedResourceDEV ( resource , props ) ;
3750
+ }
3751
+
3752
+ pushLinkImpl ( resource . chunks , resource . props ) ;
3753
+ }
3754
+
3755
+ if ( props . fetchPriority === 'high' || resources . highImagePreloads . size < 10 ) {
3756
+ resources . highImagePreloads . add ( resource ) ;
3757
+ } else {
3758
+ resources . bulkPreloads . add ( resource ) ;
3759
+ }
3760
+ }
3761
+
3762
+ return pushSelfClosing ( target , props , 'img' ) ;
3763
+ }
3764
+
3696
3765
function pushSelfClosing ( target , props , tag ) {
3697
3766
target . push ( startChunkForTag ( tag ) ) ;
3698
3767
@@ -4263,6 +4332,11 @@ function pushStartInstance(target, type, props, resources, responseState, format
4263
4332
{
4264
4333
return pushStartPreformattedElement ( target , props , type ) ;
4265
4334
}
4335
+
4336
+ case 'img' :
4337
+ {
4338
+ return pushImg ( target , props , resources ) ;
4339
+ }
4266
4340
// Omitted close tags
4267
4341
4268
4342
case 'base' :
@@ -4271,7 +4345,6 @@ function pushStartInstance(target, type, props, resources, responseState, format
4271
4345
case 'col' :
4272
4346
case 'embed' :
4273
4347
case 'hr' :
4274
- case 'img' :
4275
4348
case 'keygen' :
4276
4349
case 'param' :
4277
4350
case 'source' :
@@ -5160,14 +5233,16 @@ function writePreamble(destination, resources, responseState, willFlushAllSegmen
5160
5233
5161
5234
preconnectChunks . length = 0 ;
5162
5235
resources . fontPreloads . forEach ( flushResourceInPreamble , destination ) ;
5163
- resources . fontPreloads . clear ( ) ; // Flush unblocked stylesheets by precedence
5236
+ resources . fontPreloads . clear ( ) ;
5237
+ resources . highImagePreloads . forEach ( flushResourceInPreamble , destination ) ;
5238
+ resources . highImagePreloads . clear ( ) ; // Flush unblocked stylesheets by precedence
5164
5239
5165
5240
resources . precedences . forEach ( flushAllStylesInPreamble , destination ) ;
5166
5241
resources . bootstrapScripts . forEach ( flushResourceInPreamble , destination ) ;
5167
5242
resources . scripts . forEach ( flushResourceInPreamble , destination ) ;
5168
5243
resources . scripts . clear ( ) ;
5169
- resources . explicitPreloads . forEach ( flushResourceInPreamble , destination ) ;
5170
- resources . explicitPreloads . clear ( ) ; // Write embedding preloadChunks
5244
+ resources . bulkPreloads . forEach ( flushResourceInPreamble , destination ) ;
5245
+ resources . bulkPreloads . clear ( ) ; // Write embedding preloadChunks
5171
5246
5172
5247
var preloadChunks = responseState . preloadChunks ;
5173
5248
@@ -5215,16 +5290,18 @@ function writeHoistables(destination, resources, responseState) {
5215
5290
5216
5291
preconnectChunks . length = 0 ;
5217
5292
resources . fontPreloads . forEach ( flushResourceLate , destination ) ;
5218
- resources . fontPreloads . clear ( ) ; // Preload any stylesheets. these will emit in a render instruction that follows this
5293
+ resources . fontPreloads . clear ( ) ;
5294
+ resources . highImagePreloads . forEach ( flushResourceInPreamble , destination ) ;
5295
+ resources . highImagePreloads . clear ( ) ; // Preload any stylesheets. these will emit in a render instruction that follows this
5219
5296
// but we want to kick off preloading as soon as possible
5220
5297
5221
5298
resources . precedences . forEach ( preloadLateStyles , destination ) ; // bootstrap scripts should flush above script priority but these can only flush in the preamble
5222
5299
// so we elide the code here for performance
5223
5300
5224
5301
resources . scripts . forEach ( flushResourceLate , destination ) ;
5225
5302
resources . scripts . clear ( ) ;
5226
- resources . explicitPreloads . forEach ( flushResourceLate , destination ) ;
5227
- resources . explicitPreloads . clear ( ) ; // Write embedding preloadChunks
5303
+ resources . bulkPreloads . forEach ( flushResourceLate , destination ) ;
5304
+ resources . bulkPreloads . clear ( ) ; // Write embedding preloadChunks
5228
5305
5229
5306
var preloadChunks = responseState . preloadChunks ;
5230
5307
@@ -5641,12 +5718,13 @@ function createResources() {
5641
5718
// cleared on flush
5642
5719
preconnects : new Set ( ) ,
5643
5720
fontPreloads : new Set ( ) ,
5721
+ highImagePreloads : new Set ( ) ,
5644
5722
// usedImagePreloads: new Set(),
5645
5723
precedences : new Map ( ) ,
5646
5724
stylePrecedences : new Map ( ) ,
5647
5725
bootstrapScripts : new Set ( ) ,
5648
5726
scripts : new Set ( ) ,
5649
- explicitPreloads : new Set ( ) ,
5727
+ bulkPreloads : new Set ( ) ,
5650
5728
// like a module global for currently rendering boundary
5651
5729
boundaryResources : null
5652
5730
} ;
@@ -5803,19 +5881,7 @@ function preload(href, options) {
5803
5881
// by varying the href. this is an edge case but it is the most correct behavior.
5804
5882
var imageSrcSet = options . imageSrcSet ,
5805
5883
imageSizes = options . imageSizes ;
5806
- var uniquePart = '' ;
5807
-
5808
- if ( typeof imageSrcSet === 'string' && imageSrcSet !== '' ) {
5809
- uniquePart += '[' + imageSrcSet + ']' ;
5810
-
5811
- if ( typeof imageSizes === 'string' ) {
5812
- uniquePart += '[' + imageSizes + ']' ;
5813
- }
5814
- } else {
5815
- uniquePart += '[][]' + href ;
5816
- }
5817
-
5818
- key = getResourceKey ( as , uniquePart ) ;
5884
+ key = getImagePreloadKey ( href , imageSrcSet , imageSizes ) ;
5819
5885
} else {
5820
5886
key = getResourceKey ( as , href ) ;
5821
5887
}
@@ -5874,8 +5940,10 @@ function preload(href, options) {
5874
5940
5875
5941
if ( as === 'font' ) {
5876
5942
resources . fontPreloads . add ( resource ) ;
5943
+ } else if ( as === 'image' && options . fetchPriority === 'high' ) {
5944
+ resources . highImagePreloads . add ( resource ) ;
5877
5945
} else {
5878
- resources . explicitPreloads . add ( resource ) ;
5946
+ resources . bulkPreloads . add ( resource ) ;
5879
5947
}
5880
5948
5881
5949
flushResources ( request ) ;
0 commit comments