@@ -499,22 +499,26 @@ const HTML_COLGROUP_MODE = 8;
499
499
500
500
type InsertionMode = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 ;
501
501
502
+ const NO_SCOPE = /* */ 0b00 ;
503
+ const NOSCRIPT_SCOPE = /* */ 0b01 ;
504
+ const PICTURE_SCOPE = /* */ 0b10 ;
505
+
502
506
// Lets us keep track of contextual state and pick it back up after suspending.
503
507
export type FormatContext = {
504
508
insertionMode : InsertionMode , // root/svg/html/mathml/table
505
509
selectedValue : null | string | Array < string > , // the selected value(s) inside a <select>, or null outside <select>
506
- noscriptTagInScope : boolean ,
510
+ tagScope : number ,
507
511
} ;
508
512
509
513
function createFormatContext (
510
514
insertionMode : InsertionMode ,
511
515
selectedValue : null | string ,
512
- noscriptTagInScope : boolean ,
516
+ tagScope : number ,
513
517
) : FormatContext {
514
518
return {
515
519
insertionMode,
516
520
selectedValue,
517
- noscriptTagInScope ,
521
+ tagScope ,
518
522
} ;
519
523
}
520
524
@@ -525,7 +529,7 @@ export function createRootFormatContext(namespaceURI?: string): FormatContext {
525
529
: namespaceURI === 'http://www.w3.org/1998/Math/MathML'
526
530
? MATHML_MODE
527
531
: ROOT_HTML_MODE ;
528
- return createFormatContext ( insertionMode , null , false ) ;
532
+ return createFormatContext ( insertionMode , null , NO_SCOPE ) ;
529
533
}
530
534
531
535
export function getChildFormatContext (
@@ -535,80 +539,70 @@ export function getChildFormatContext(
535
539
) : FormatContext {
536
540
switch ( type ) {
537
541
case 'noscript' :
538
- return createFormatContext ( HTML_MODE , null , true ) ;
542
+ return createFormatContext (
543
+ HTML_MODE ,
544
+ null ,
545
+ parentContext . tagScope | NOSCRIPT_SCOPE ,
546
+ ) ;
539
547
case 'select' :
540
548
return createFormatContext (
541
549
HTML_MODE ,
542
550
props . value != null ? props . value : props . defaultValue ,
543
- parentContext . noscriptTagInScope ,
551
+ parentContext . tagScope ,
544
552
) ;
545
553
case 'svg' :
554
+ return createFormatContext ( SVG_MODE , null , parentContext . tagScope ) ;
555
+ case 'picture' :
546
556
return createFormatContext (
547
- SVG_MODE ,
557
+ HTML_MODE ,
548
558
null ,
549
- parentContext . noscriptTagInScope ,
559
+ parentContext . tagScope | PICTURE_SCOPE ,
550
560
) ;
551
561
case 'math' :
552
- return createFormatContext (
553
- MATHML_MODE ,
554
- null ,
555
- parentContext . noscriptTagInScope ,
556
- ) ;
562
+ return createFormatContext ( MATHML_MODE , null , parentContext . tagScope ) ;
557
563
case 'foreignObject' :
558
- return createFormatContext (
559
- HTML_MODE ,
560
- null ,
561
- parentContext . noscriptTagInScope ,
562
- ) ;
564
+ return createFormatContext ( HTML_MODE , null , parentContext . tagScope ) ;
563
565
// Table parents are special in that their children can only be created at all if they're
564
566
// wrapped in a table parent. So we need to encode that we're entering this mode.
565
567
case 'table' :
566
- return createFormatContext (
567
- HTML_TABLE_MODE ,
568
- null ,
569
- parentContext . noscriptTagInScope ,
570
- ) ;
568
+ return createFormatContext ( HTML_TABLE_MODE , null , parentContext . tagScope ) ;
571
569
case 'thead' :
572
570
case 'tbody' :
573
571
case 'tfoot' :
574
572
return createFormatContext (
575
573
HTML_TABLE_BODY_MODE ,
576
574
null ,
577
- parentContext . noscriptTagInScope ,
575
+ parentContext . tagScope ,
578
576
) ;
579
577
case 'colgroup' :
580
578
return createFormatContext (
581
579
HTML_COLGROUP_MODE ,
582
580
null ,
583
- parentContext . noscriptTagInScope ,
581
+ parentContext . tagScope ,
584
582
) ;
585
583
case 'tr' :
586
584
return createFormatContext (
587
585
HTML_TABLE_ROW_MODE ,
588
586
null ,
589
- parentContext . noscriptTagInScope ,
587
+ parentContext . tagScope ,
590
588
) ;
591
589
}
592
590
if ( parentContext . insertionMode >= HTML_TABLE_MODE ) {
593
591
// Whatever tag this was, it wasn't a table parent or other special parent, so we must have
594
592
// entered plain HTML again.
595
- return createFormatContext (
596
- HTML_MODE ,
597
- null ,
598
- parentContext . noscriptTagInScope ,
599
- ) ;
593
+ return createFormatContext ( HTML_MODE , null , parentContext . tagScope ) ;
600
594
}
601
595
if ( parentContext . insertionMode === ROOT_HTML_MODE ) {
602
596
if ( type === 'html' ) {
603
597
// We've emitted the root and is now in <html> mode.
604
- return createFormatContext ( HTML_HTML_MODE , null , false ) ;
598
+ return createFormatContext ( HTML_HTML_MODE , null , parentContext . tagScope ) ;
605
599
} else {
606
600
// We've emitted the root and is now in plain HTML mode.
607
- return createFormatContext ( HTML_MODE , null , false ) ;
601
+ return createFormatContext ( HTML_MODE , null , parentContext . tagScope ) ;
608
602
}
609
603
} else if ( parentContext . insertionMode === HTML_HTML_MODE ) {
610
604
// We've emitted the document element and is now in plain HTML mode.
611
- return createFormatContext ( HTML_MODE , null , false ) ;
605
+ return createFormatContext ( HTML_MODE , null , parentContext . tagScope ) ;
612
606
}
613
607
return parentContext ;
614
608
}
@@ -2457,12 +2451,14 @@ function pushImg(
2457
2451
target : Array < Chunk | PrecomputedChunk > ,
2458
2452
props : Object ,
2459
2453
resumableState : ResumableState ,
2454
+ pictureTagInScope : boolean ,
2460
2455
) : null {
2461
2456
const { src, srcSet} = props ;
2462
2457
if (
2463
2458
props . loading !== 'lazy' &&
2464
2459
( typeof src === 'string' || typeof srcSet === 'string' ) &&
2465
2460
props . fetchPriority !== 'low' &&
2461
+ pictureTagInScope === false &&
2466
2462
// We exclude data URIs in src and srcSet since these should not be preloaded
2467
2463
! (
2468
2464
typeof src === 'string' &&
@@ -3230,7 +3226,7 @@ export function pushStartInstance(
3230
3226
props ,
3231
3227
renderState ,
3232
3228
formatContext . insertionMode ,
3233
- formatContext . noscriptTagInScope ,
3229
+ ! ! ( formatContext . tagScope & NOSCRIPT_SCOPE ) ,
3234
3230
)
3235
3231
: pushStartTitle ( target , props ) ;
3236
3232
case 'link' :
@@ -3241,7 +3237,7 @@ export function pushStartInstance(
3241
3237
renderState ,
3242
3238
textEmbedded ,
3243
3239
formatContext . insertionMode ,
3244
- formatContext . noscriptTagInScope ,
3240
+ ! ! ( formatContext . tagScope & NOSCRIPT_SCOPE ) ,
3245
3241
) ;
3246
3242
case 'script' :
3247
3243
return enableFloat
@@ -3251,7 +3247,7 @@ export function pushStartInstance(
3251
3247
resumableState ,
3252
3248
textEmbedded ,
3253
3249
formatContext . insertionMode ,
3254
- formatContext . noscriptTagInScope ,
3250
+ ! ! ( formatContext . tagScope & NOSCRIPT_SCOPE ) ,
3255
3251
)
3256
3252
: pushStartGenericElement ( target , props , type ) ;
3257
3253
case 'style' :
@@ -3262,7 +3258,7 @@ export function pushStartInstance(
3262
3258
renderState ,
3263
3259
textEmbedded ,
3264
3260
formatContext . insertionMode ,
3265
- formatContext . noscriptTagInScope ,
3261
+ ! ! ( formatContext . tagScope & NOSCRIPT_SCOPE ) ,
3266
3262
) ;
3267
3263
case 'meta' :
3268
3264
return pushMeta (
@@ -3271,7 +3267,7 @@ export function pushStartInstance(
3271
3267
renderState ,
3272
3268
textEmbedded ,
3273
3269
formatContext . insertionMode ,
3274
- formatContext . noscriptTagInScope ,
3270
+ ! ! ( formatContext . tagScope & NOSCRIPT_SCOPE ) ,
3275
3271
) ;
3276
3272
// Newline eating tags
3277
3273
case 'listing' :
@@ -3280,7 +3276,12 @@ export function pushStartInstance(
3280
3276
}
3281
3277
case 'img' : {
3282
3278
return enableFloat
3283
- ? pushImg ( target , props , resumableState )
3279
+ ? pushImg (
3280
+ target ,
3281
+ props ,
3282
+ resumableState ,
3283
+ ! ! ( formatContext . tagScope & PICTURE_SCOPE ) ,
3284
+ )
3284
3285
: pushSelfClosing ( target , props , type ) ;
3285
3286
}
3286
3287
// Omitted close tags
0 commit comments