@@ -59,6 +59,7 @@ export const isPrimaryRenderer = true;
59
59
60
60
// Per response, global state that is not contextual to the rendering subtree.
61
61
export type ResponseState = {
62
+ startInlineScript : PrecomputedChunk ,
62
63
placeholderPrefix : PrecomputedChunk ,
63
64
segmentPrefix : PrecomputedChunk ,
64
65
boundaryPrefix : string ,
@@ -71,12 +72,22 @@ export type ResponseState = {
71
72
...
72
73
} ;
73
74
75
+ const startInlineScript = stringToPrecomputedChunk ( '<script>' ) ;
76
+
74
77
// Allows us to keep track of what we've already written so we can refer back to it.
75
78
export function createResponseState (
76
79
identifierPrefix : string | void ,
80
+ nonce : string | void ,
77
81
) : ResponseState {
78
82
const idPrefix = identifierPrefix === undefined ? '' : identifierPrefix ;
83
+ const inlineScriptWithNonce =
84
+ nonce === undefined
85
+ ? startInlineScript
86
+ : stringToPrecomputedChunk (
87
+ '<script nonce="' + escapeTextForBrowser ( nonce ) + '">' ,
88
+ ) ;
79
89
return {
90
+ startInlineScript : inlineScriptWithNonce ,
80
91
placeholderPrefix : stringToPrecomputedChunk ( idPrefix + 'P:' ) ,
81
92
segmentPrefix : stringToPrecomputedChunk ( idPrefix + 'S:' ) ,
82
93
boundaryPrefix : idPrefix + 'B:' ,
@@ -1689,9 +1700,9 @@ const clientRenderFunction =
1689
1700
'function $RX(a){if(a=document.getElementById(a))a=a.previousSibling,a.data="$!",a._reactRetry&&a._reactRetry()}' ;
1690
1701
1691
1702
const completeSegmentScript1Full = stringToPrecomputedChunk (
1692
- '<script>' + completeSegmentFunction + ';$RS("' ,
1703
+ completeSegmentFunction + ';$RS("' ,
1693
1704
) ;
1694
- const completeSegmentScript1Partial = stringToPrecomputedChunk ( '<script> $RS("' ) ;
1705
+ const completeSegmentScript1Partial = stringToPrecomputedChunk ( '$RS("' ) ;
1695
1706
const completeSegmentScript2 = stringToPrecomputedChunk ( '","' ) ;
1696
1707
const completeSegmentScript3 = stringToPrecomputedChunk ( '")</script>' ) ;
1697
1708
@@ -1700,6 +1711,7 @@ export function writeCompletedSegmentInstruction(
1700
1711
responseState : ResponseState ,
1701
1712
contentSegmentID : number ,
1702
1713
) : boolean {
1714
+ writeChunk ( destination , responseState . startInlineScript ) ;
1703
1715
if ( ! responseState . sentCompleteSegmentFunction ) {
1704
1716
// The first time we write this, we'll need to include the full implementation.
1705
1717
responseState . sentCompleteSegmentFunction = true ;
@@ -1718,11 +1730,9 @@ export function writeCompletedSegmentInstruction(
1718
1730
}
1719
1731
1720
1732
const completeBoundaryScript1Full = stringToPrecomputedChunk (
1721
- '<script>' + completeBoundaryFunction + ';$RC("' ,
1722
- ) ;
1723
- const completeBoundaryScript1Partial = stringToPrecomputedChunk (
1724
- '<script>$RC("' ,
1733
+ completeBoundaryFunction + ';$RC("' ,
1725
1734
) ;
1735
+ const completeBoundaryScript1Partial = stringToPrecomputedChunk ( '$RC("' ) ;
1726
1736
const completeBoundaryScript2 = stringToPrecomputedChunk ( '","' ) ;
1727
1737
const completeBoundaryScript3 = stringToPrecomputedChunk ( '")</script>' ) ;
1728
1738
@@ -1732,6 +1742,7 @@ export function writeCompletedBoundaryInstruction(
1732
1742
boundaryID : SuspenseBoundaryID ,
1733
1743
contentSegmentID : number ,
1734
1744
) : boolean {
1745
+ writeChunk ( destination , responseState . startInlineScript ) ;
1735
1746
if ( ! responseState . sentCompleteBoundaryFunction ) {
1736
1747
// The first time we write this, we'll need to include the full implementation.
1737
1748
responseState . sentCompleteBoundaryFunction = true ;
@@ -1756,16 +1767,17 @@ export function writeCompletedBoundaryInstruction(
1756
1767
}
1757
1768
1758
1769
const clientRenderScript1Full = stringToPrecomputedChunk (
1759
- '<script>' + clientRenderFunction + ';$RX("' ,
1770
+ clientRenderFunction + ';$RX("' ,
1760
1771
) ;
1761
- const clientRenderScript1Partial = stringToPrecomputedChunk ( '<script> $RX("' ) ;
1772
+ const clientRenderScript1Partial = stringToPrecomputedChunk ( '$RX("' ) ;
1762
1773
const clientRenderScript2 = stringToPrecomputedChunk ( '")</script>' ) ;
1763
1774
1764
1775
export function writeClientRenderBoundaryInstruction (
1765
1776
destination : Destination ,
1766
1777
responseState : ResponseState ,
1767
1778
boundaryID : SuspenseBoundaryID ,
1768
1779
) : boolean {
1780
+ writeChunk ( destination , responseState . startInlineScript ) ;
1769
1781
if ( ! responseState . sentClientRenderFunction ) {
1770
1782
// The first time we write this, we'll need to include the full implementation.
1771
1783
responseState . sentClientRenderFunction = true ;
0 commit comments