@@ -2563,6 +2563,12 @@ const completeBoundaryOrContainerScriptEnd = stringToPrecomputedChunk(
2563
2563
')</script>' ,
2564
2564
) ;
2565
2565
2566
+ const bootstrapContainerOpenStart = stringToPrecomputedChunk (
2567
+ '<template id="bs:' ,
2568
+ ) ;
2569
+ const bootstrapContainerOpenEnd = stringToPrecomputedChunk ( '">' ) ;
2570
+ const bootstrapContainerClose = stringToPrecomputedChunk ( '</template>' ) ;
2571
+
2566
2572
const completeContainerData1 = stringToPrecomputedChunk (
2567
2573
'<template data-rci="c" data-bid="' ,
2568
2574
) ;
@@ -2581,7 +2587,11 @@ const completeBoundaryOrContainerData2 = stringToPrecomputedChunk(
2581
2587
const completeBoundaryOrContainerData3 = stringToPrecomputedChunk (
2582
2588
'" data-sty="' ,
2583
2589
) ;
2584
- const completeBoundaryOrContainerDataEnd = dataElementQuotedEnd ;
2590
+ const completeBoundaryOrContainerDataOpenEnd = stringToPrecomputedChunk ( '">' ) ;
2591
+ const completeBoundaryOrContainerDataClose = stringToPrecomputedChunk (
2592
+ '</template>' ,
2593
+ ) ;
2594
+ const completeBoundaryOrContainerDataEmptyEnd = dataElementQuotedEnd ;
2585
2595
2586
2596
export function writeCompletedBoundaryInstruction (
2587
2597
destination : Destination ,
@@ -2605,97 +2615,184 @@ export function writeCompletedBoundaryInstruction(
2605
2615
responseState . streamingFormat === ScriptStreamingFormat ;
2606
2616
let r = true ;
2607
2617
if ( scriptFormat ) {
2608
- writeChunk ( destination , responseState . startInlineScript ) ;
2609
2618
if ( enableFloat && hasStyleDependencies ) {
2610
- if ( ! responseState . sentStyleInsertionFunction ) {
2611
- responseState . sentStyleInsertionFunction = true ;
2612
- writeChunk ( destination , clonePrecomputedChunk ( styleInsertionFunction ) ) ;
2613
- }
2614
2619
if ( boundaryID === responseState . containerBoundaryID ) {
2620
+ // We emit the bootstrap chunks unto a template container with an id
2621
+ // formed from the root segment ID. The insertion script will inject
2622
+ // the bootstrap scripts into the DOM after revealing the content.
2623
+ // We don't do this for cases where there are no style dependencies because
2624
+ // the content swap is synchronous and will therefore always complete before
2625
+ // the bootstrap scripts run
2626
+ const bootstrapChunks = responseState . bootstrapChunks ;
2627
+ if ( bootstrapChunks . length ) {
2628
+ writeChunk ( destination , bootstrapContainerOpenStart ) ;
2629
+ writeChunk ( destination , responseState . segmentPrefix ) ;
2630
+ writeChunk ( destination , formattedContentID ) ;
2631
+ writeChunk ( destination , bootstrapContainerOpenEnd ) ;
2632
+ for ( let i = 0 ; i < bootstrapChunks . length ; i ++ ) {
2633
+ writeChunk ( destination , bootstrapChunks [ i ] ) ;
2634
+ }
2635
+ writeChunk ( destination , bootstrapContainerClose ) ;
2636
+ }
2637
+
2638
+ writeChunk ( destination , responseState . startInlineScript ) ;
2639
+ if ( ! responseState . sentStyleInsertionFunction ) {
2640
+ responseState . sentStyleInsertionFunction = true ;
2641
+ writeChunk (
2642
+ destination ,
2643
+ clonePrecomputedChunk ( styleInsertionFunction ) ,
2644
+ ) ;
2645
+ }
2615
2646
if ( ! responseState . sentCompleteContainerFunction ) {
2616
2647
responseState . sentCompleteContainerFunction = true ;
2617
2648
writeChunk ( destination , completeContainerFunction ) ;
2618
2649
}
2619
2650
writeChunk ( destination , completeContainerWithStylesScript1 ) ;
2651
+ writeChunk ( destination , boundaryID ) ;
2652
+ writeChunk ( destination , completeBoundaryOrContainerScript2 ) ;
2653
+ writeChunk ( destination , responseState . segmentPrefix ) ;
2654
+ writeChunk ( destination , formattedContentID ) ;
2655
+ writeChunk ( destination , completeBoundaryOrContainerScript2a ) ;
2656
+ writeStyleResourceDependenciesInJS ( destination , boundaryResources ) ;
2657
+ return writeChunkAndReturn (
2658
+ destination ,
2659
+ completeBoundaryOrContainerScriptEnd ,
2660
+ ) ;
2620
2661
} else {
2662
+ writeChunk ( destination , responseState . startInlineScript ) ;
2663
+ if ( ! responseState . sentStyleInsertionFunction ) {
2664
+ responseState . sentStyleInsertionFunction = true ;
2665
+ writeChunk (
2666
+ destination ,
2667
+ clonePrecomputedChunk ( styleInsertionFunction ) ,
2668
+ ) ;
2669
+ }
2621
2670
if ( ! responseState . sentCompleteBoundaryFunction ) {
2622
2671
responseState . sentCompleteBoundaryFunction = true ;
2623
2672
writeChunk ( destination , completeBoundaryFunction ) ;
2624
2673
}
2625
2674
writeChunk ( destination , completeBoundaryWithStylesScript1 ) ;
2675
+ writeChunk ( destination , boundaryID ) ;
2676
+ writeChunk ( destination , completeBoundaryOrContainerScript2 ) ;
2677
+ writeChunk ( destination , responseState . segmentPrefix ) ;
2678
+ writeChunk ( destination , formattedContentID ) ;
2679
+ writeChunk ( destination , completeBoundaryOrContainerScript2a ) ;
2680
+ writeStyleResourceDependenciesInJS ( destination , boundaryResources ) ;
2681
+ return writeChunkAndReturn (
2682
+ destination ,
2683
+ completeBoundaryOrContainerScriptEnd ,
2684
+ ) ;
2626
2685
}
2627
- writeChunk ( destination , boundaryID ) ;
2628
- writeChunk ( destination , completeBoundaryOrContainerScript2 ) ;
2629
- writeChunk ( destination , responseState . segmentPrefix ) ;
2630
- writeChunk ( destination , formattedContentID ) ;
2631
- writeChunk ( destination , completeBoundaryOrContainerScript2a ) ;
2632
- writeStyleResourceDependenciesInJS ( destination , boundaryResources ) ;
2633
- r = writeChunkAndReturn (
2634
- destination ,
2635
- completeBoundaryOrContainerScriptEnd ,
2636
- ) ;
2637
2686
} else {
2638
2687
if ( boundaryID === responseState . containerBoundaryID ) {
2688
+ writeChunk ( destination , responseState . startInlineScript ) ;
2639
2689
if ( ! responseState . sentCompleteContainerFunction ) {
2640
2690
responseState . sentCompleteContainerFunction = true ;
2641
2691
writeChunk ( destination , completeContainerFunction ) ;
2642
2692
}
2643
2693
writeChunk ( destination , completeContainerScript1 ) ;
2694
+ writeChunk ( destination , boundaryID ) ;
2695
+ writeChunk ( destination , completeBoundaryOrContainerScript2 ) ;
2696
+ writeChunk ( destination , responseState . segmentPrefix ) ;
2697
+ writeChunk ( destination , formattedContentID ) ;
2698
+ writeChunk ( destination , completeBoundaryOrContainerScript3 ) ;
2699
+ r = writeChunkAndReturn (
2700
+ destination ,
2701
+ completeBoundaryOrContainerScriptEnd ,
2702
+ ) ;
2703
+
2704
+ // We emit bootstrap scripts after the completeContainer instruction
2705
+ // because we want to ensure the reveal ocurrs before the bootstrap
2706
+ // scripts execute. Notice that unlike with the styles case the scripts
2707
+ // are not embedded in a template
2708
+ const bootstrapChunks = responseState . bootstrapChunks ;
2709
+ let i = 0 ;
2710
+ for ( ; i < bootstrapChunks . length - 1 ; i ++ ) {
2711
+ writeChunk ( destination , bootstrapChunks [ i ] ) ;
2712
+ }
2713
+ if ( i < bootstrapChunks . length ) {
2714
+ r = writeChunkAndReturn ( destination , bootstrapChunks [ i ] ) ;
2715
+ }
2716
+ return r ;
2644
2717
} else {
2718
+ writeChunk ( destination , responseState . startInlineScript ) ;
2645
2719
if ( ! responseState . sentCompleteBoundaryFunction ) {
2646
2720
responseState . sentCompleteBoundaryFunction = true ;
2647
2721
writeChunk ( destination , completeBoundaryFunction ) ;
2648
2722
}
2649
2723
writeChunk ( destination , completeBoundaryScript1 ) ;
2724
+ writeChunk ( destination , boundaryID ) ;
2725
+ writeChunk ( destination , completeBoundaryOrContainerScript2 ) ;
2726
+ writeChunk ( destination , responseState . segmentPrefix ) ;
2727
+ writeChunk ( destination , formattedContentID ) ;
2728
+ writeChunk ( destination , completeBoundaryOrContainerScript3 ) ;
2729
+ return writeChunkAndReturn (
2730
+ destination ,
2731
+ completeBoundaryOrContainerScriptEnd ,
2732
+ ) ;
2650
2733
}
2651
- writeChunk ( destination , boundaryID ) ;
2652
- writeChunk ( destination , completeBoundaryOrContainerScript2 ) ;
2653
- writeChunk ( destination , responseState . segmentPrefix ) ;
2654
- writeChunk ( destination , formattedContentID ) ;
2655
- writeChunk ( destination , completeBoundaryOrContainerScript3 ) ;
2656
- r = writeChunkAndReturn (
2657
- destination ,
2658
- completeBoundaryOrContainerScriptEnd ,
2659
- ) ;
2660
2734
}
2661
2735
} else {
2662
2736
if ( enableFloat && hasStyleDependencies ) {
2663
2737
if ( boundaryID === responseState . containerBoundaryID ) {
2664
2738
writeChunk ( destination , completeContainerWithStylesData1 ) ;
2739
+ writeChunk ( destination , boundaryID ) ;
2740
+ writeChunk ( destination , completeBoundaryOrContainerData2 ) ;
2741
+ writeChunk ( destination , responseState . segmentPrefix ) ;
2742
+ writeChunk ( destination , formattedContentID ) ;
2743
+ writeChunk ( destination , completeBoundaryOrContainerData3 ) ;
2744
+ writeStyleResourceDependenciesInAttr ( destination , boundaryResources ) ;
2745
+ writeChunk ( destination , completeBoundaryOrContainerDataOpenEnd ) ;
2746
+ const bootstrapChunks = responseState . bootstrapChunks ;
2747
+ for ( let i = 0 ; i < bootstrapChunks . length ; i ++ ) {
2748
+ writeChunk ( destination , bootstrapChunks [ i ] ) ;
2749
+ }
2750
+ return writeChunkAndReturn (
2751
+ destination ,
2752
+ completeBoundaryOrContainerDataClose ,
2753
+ ) ;
2665
2754
} else {
2666
2755
writeChunk ( destination , completeBoundaryWithStylesData1 ) ;
2756
+ writeChunk ( destination , boundaryID ) ;
2757
+ writeChunk ( destination , completeBoundaryOrContainerData2 ) ;
2758
+ writeChunk ( destination , responseState . segmentPrefix ) ;
2759
+ writeChunk ( destination , formattedContentID ) ;
2760
+ writeChunk ( destination , completeBoundaryOrContainerData3 ) ;
2761
+ writeStyleResourceDependenciesInAttr ( destination , boundaryResources ) ;
2762
+ return writeChunkAndReturn (
2763
+ destination ,
2764
+ completeBoundaryOrContainerDataEmptyEnd ,
2765
+ ) ;
2667
2766
}
2668
- writeChunk ( destination , boundaryID ) ;
2669
- writeChunk ( destination , completeBoundaryOrContainerData2 ) ;
2670
- writeChunk ( destination , responseState . segmentPrefix ) ;
2671
- writeChunk ( destination , formattedContentID ) ;
2672
- writeChunk ( destination , completeBoundaryOrContainerData3 ) ;
2673
- writeStyleResourceDependenciesInAttr ( destination , boundaryResources ) ;
2674
- r = writeChunkAndReturn ( destination , completeBoundaryOrContainerDataEnd ) ;
2675
2767
} else {
2676
2768
if ( boundaryID === responseState . containerBoundaryID ) {
2677
2769
writeChunk ( destination , completeContainerData1 ) ;
2770
+ writeChunk ( destination , boundaryID ) ;
2771
+ writeChunk ( destination , completeBoundaryOrContainerData2 ) ;
2772
+ writeChunk ( destination , responseState . segmentPrefix ) ;
2773
+ writeChunk ( destination , formattedContentID ) ;
2774
+ writeChunk ( destination , completeBoundaryOrContainerDataOpenEnd ) ;
2775
+ const bootstrapChunks = responseState . bootstrapChunks ;
2776
+ for ( let i = 0 ; i < bootstrapChunks . length ; i ++ ) {
2777
+ writeChunk ( destination , bootstrapChunks [ i ] ) ;
2778
+ }
2779
+ return writeChunkAndReturn (
2780
+ destination ,
2781
+ completeBoundaryOrContainerDataOpenEnd ,
2782
+ ) ;
2678
2783
} else {
2679
2784
writeChunk ( destination , completeBoundaryData1 ) ;
2785
+ writeChunk ( destination , boundaryID ) ;
2786
+ writeChunk ( destination , completeBoundaryOrContainerData2 ) ;
2787
+ writeChunk ( destination , responseState . segmentPrefix ) ;
2788
+ writeChunk ( destination , formattedContentID ) ;
2789
+ return writeChunkAndReturn (
2790
+ destination ,
2791
+ completeBoundaryOrContainerDataEmptyEnd ,
2792
+ ) ;
2680
2793
}
2681
- writeChunk ( destination , boundaryID ) ;
2682
- writeChunk ( destination , completeBoundaryOrContainerData2 ) ;
2683
- writeChunk ( destination , responseState . segmentPrefix ) ;
2684
- writeChunk ( destination , formattedContentID ) ;
2685
- r = writeChunkAndReturn ( destination , completeBoundaryOrContainerDataEnd ) ;
2686
2794
}
2687
2795
}
2688
- if ( boundaryID === responseState . containerBoundaryID ) {
2689
- const bootstrapChunks = responseState . bootstrapChunks ;
2690
- let i = 0 ;
2691
- for ( ; i < bootstrapChunks . length - 1 ; i ++ ) {
2692
- writeChunk ( destination , bootstrapChunks [ i ] ) ;
2693
- }
2694
- if ( i < bootstrapChunks . length ) {
2695
- return writeChunkAndReturn ( destination , bootstrapChunks [ i ] ) ;
2696
- }
2697
- }
2698
- return r ;
2699
2796
}
2700
2797
2701
2798
const clientRenderScript1Full = stringToPrecomputedChunk (
0 commit comments