@@ -153,6 +153,8 @@ export type BootstrapScriptDescriptor = {
153
153
integrity ?: string ,
154
154
} ;
155
155
// Allows us to keep track of what we've already written so we can refer back to it.
156
+ // if passed externalRuntimeConfig and the enableFizzExternalRuntime feature flag
157
+ // is set, the server will send instructions via data attributes (instead of inline scripts)
156
158
export function createResponseState (
157
159
identifierPrefix : string | void ,
158
160
nonce : string | void ,
@@ -2291,7 +2293,7 @@ const completeSegmentScript1Full = stringToPrecomputedChunk(
2291
2293
) ;
2292
2294
const completeSegmentScript1Partial = stringToPrecomputedChunk ( '$RS("' ) ;
2293
2295
const completeSegmentScript2 = stringToPrecomputedChunk ( '","' ) ;
2294
- const completeSegmentScript3 = stringToPrecomputedChunk ( '")</script>' ) ;
2296
+ const completeSegmentScriptEnd = stringToPrecomputedChunk ( '")</script>' ) ;
2295
2297
2296
2298
export function writeCompletedSegmentInstruction (
2297
2299
destination : Destination ,
@@ -2307,13 +2309,16 @@ export function writeCompletedSegmentInstruction(
2307
2309
// Future calls can just reuse the same function.
2308
2310
writeChunk ( destination , completeSegmentScript1Partial ) ;
2309
2311
}
2312
+
2313
+ // Write function arguments, which are string literals
2310
2314
writeChunk ( destination , responseState . segmentPrefix ) ;
2311
2315
const formattedID = stringToChunk ( contentSegmentID . toString ( 16 ) ) ;
2312
2316
writeChunk ( destination , formattedID ) ;
2313
2317
writeChunk ( destination , completeSegmentScript2 ) ;
2314
2318
writeChunk ( destination , responseState . placeholderPrefix ) ;
2315
2319
writeChunk ( destination , formattedID ) ;
2316
- return writeChunkAndReturn ( destination , completeSegmentScript3 ) ;
2320
+
2321
+ return writeChunkAndReturn ( destination , completeSegmentScriptEnd ) ;
2317
2322
}
2318
2323
2319
2324
const completeBoundaryScript1Full = stringToPrecomputedChunk (
@@ -2331,9 +2336,9 @@ const completeBoundaryWithStylesScript1Partial = stringToPrecomputedChunk(
2331
2336
'$RR("' ,
2332
2337
) ;
2333
2338
const completeBoundaryScript2 = stringToPrecomputedChunk ( '","' ) ;
2334
- const completeBoundaryScript2a = stringToPrecomputedChunk ( '",' ) ;
2335
- const completeBoundaryScript3 = stringToPrecomputedChunk ( '"' ) ;
2336
- const completeBoundaryScript4 = stringToPrecomputedChunk ( ')</script>' ) ;
2339
+ const completeBoundaryScript3a = stringToPrecomputedChunk ( '",' ) ;
2340
+ const completeBoundaryScript3b = stringToPrecomputedChunk ( '"' ) ;
2341
+ const completeBoundaryScriptEnd = stringToPrecomputedChunk ( ')</script>' ) ;
2337
2342
2338
2343
export function writeCompletedBoundaryInstruction (
2339
2344
destination : Destination ,
@@ -2373,26 +2378,28 @@ export function writeCompletedBoundaryInstruction(
2373
2378
) ;
2374
2379
}
2375
2380
2381
+ // Write function arguments, which are string literals and array
2376
2382
const formattedContentID = stringToChunk ( contentSegmentID . toString ( 16 ) ) ;
2377
2383
writeChunk ( destination , boundaryID ) ;
2378
2384
writeChunk ( destination , completeBoundaryScript2 ) ;
2379
2385
writeChunk ( destination , responseState . segmentPrefix ) ;
2380
2386
writeChunk ( destination , formattedContentID ) ;
2381
2387
if ( enableFloat && hasStyleDependencies ) {
2382
- writeChunk ( destination , completeBoundaryScript2a ) ;
2388
+ writeChunk ( destination , completeBoundaryScript3a ) ;
2389
+ // boundaryResources encodes an array literal
2383
2390
writeStyleResourceDependencies ( destination , boundaryResources ) ;
2384
2391
} else {
2385
- writeChunk ( destination , completeBoundaryScript3 ) ;
2392
+ writeChunk ( destination , completeBoundaryScript3b ) ;
2386
2393
}
2387
- return writeChunkAndReturn ( destination , completeBoundaryScript4 ) ;
2394
+ return writeChunkAndReturn ( destination , completeBoundaryScriptEnd ) ;
2388
2395
}
2389
2396
2390
2397
const clientRenderScript1Full = stringToPrecomputedChunk (
2391
2398
clientRenderFunction + ';$RX("' ,
2392
2399
) ;
2393
2400
const clientRenderScript1Partial = stringToPrecomputedChunk ( '$RX("' ) ;
2394
2401
const clientRenderScript1A = stringToPrecomputedChunk ( '"' ) ;
2395
- const clientRenderScript2 = stringToPrecomputedChunk ( ')</script>' ) ;
2402
+ const clientRenderScriptEnd = stringToPrecomputedChunk ( ')</script>' ) ;
2396
2403
const clientRenderErrorScriptArgInterstitial = stringToPrecomputedChunk ( ',' ) ;
2397
2404
2398
2405
export function writeClientRenderBoundaryInstruction (
@@ -2418,31 +2425,34 @@ export function writeClientRenderBoundaryInstruction(
2418
2425
'An ID must have been assigned before we can complete the boundary.' ,
2419
2426
) ;
2420
2427
}
2421
-
2428
+ // Write function arguments, which are string literals
2422
2429
writeChunk ( destination , boundaryID ) ;
2423
2430
writeChunk ( destination , clientRenderScript1A ) ;
2424
2431
if ( errorDigest || errorMessage || errorComponentStack ) {
2432
+ // ,"JSONString"
2425
2433
writeChunk ( destination , clientRenderErrorScriptArgInterstitial ) ;
2426
2434
writeChunk (
2427
2435
destination ,
2428
2436
stringToChunk ( escapeJSStringsForInstructionScripts ( errorDigest || '' ) ) ,
2429
2437
) ;
2430
2438
}
2431
2439
if ( errorMessage || errorComponentStack ) {
2440
+ // ,"JSONString"
2432
2441
writeChunk ( destination , clientRenderErrorScriptArgInterstitial ) ;
2433
2442
writeChunk (
2434
2443
destination ,
2435
2444
stringToChunk ( escapeJSStringsForInstructionScripts ( errorMessage || '' ) ) ,
2436
2445
) ;
2437
2446
}
2438
2447
if ( errorComponentStack ) {
2448
+ // ,"JSONString"
2439
2449
writeChunk ( destination , clientRenderErrorScriptArgInterstitial ) ;
2440
2450
writeChunk (
2441
2451
destination ,
2442
2452
stringToChunk ( escapeJSStringsForInstructionScripts ( errorComponentStack ) ) ,
2443
2453
) ;
2444
2454
}
2445
- return writeChunkAndReturn ( destination , clientRenderScript2 ) ;
2455
+ return writeChunkAndReturn ( destination , clientRenderScriptEnd ) ;
2446
2456
}
2447
2457
2448
2458
const regexForJSStringsInInstructionScripts = / [ < \u2028\u2029 ] / g ;
@@ -2743,6 +2753,16 @@ const arraySubsequentOpenBracket = stringToPrecomputedChunk(',[');
2743
2753
const arrayInterstitial = stringToPrecomputedChunk ( ',' ) ;
2744
2754
const arrayCloseBracket = stringToPrecomputedChunk ( ']' ) ;
2745
2755
2756
+ function writeStyleResourceObject ( destination : Destination , str : string ) {
2757
+ // write "script_escaped_string", since this is writing to a script tag
2758
+ // and will be evaluated as a string literal inside an array literal
2759
+ writeChunk (
2760
+ destination ,
2761
+ stringToChunk ( escapeJSObjectForInstructionScripts ( str ) ) ,
2762
+ ) ;
2763
+ // TODO(mofeiZ): will add a data writer format here in a later PR
2764
+ }
2765
+
2746
2766
function writeStyleResourceDependencies (
2747
2767
destination : Destination ,
2748
2768
boundaryResources : BoundaryResources ,
@@ -2787,10 +2807,7 @@ function writeStyleResourceDependencyHrefOnly(
2787
2807
checkAttributeStringCoercion ( href , 'href' ) ;
2788
2808
}
2789
2809
const coercedHref = '' + ( href : any ) ;
2790
- writeChunk (
2791
- destination ,
2792
- stringToChunk ( escapeJSObjectForInstructionScripts ( coercedHref ) ) ,
2793
- ) ;
2810
+ writeStyleResourceObject ( destination , coercedHref ) ;
2794
2811
}
2795
2812
2796
2813
function writeStyleResourceDependency (
@@ -2804,20 +2821,15 @@ function writeStyleResourceDependency(
2804
2821
}
2805
2822
const coercedHref = '' + ( href : any ) ;
2806
2823
sanitizeURL ( coercedHref ) ;
2807
- writeChunk (
2808
- destination ,
2809
- stringToChunk ( escapeJSObjectForInstructionScripts ( coercedHref ) ) ,
2810
- ) ;
2824
+ writeStyleResourceObject ( destination , coercedHref ) ;
2811
2825
2812
2826
if ( __DEV__ ) {
2813
2827
checkAttributeStringCoercion ( precedence , 'precedence' ) ;
2814
2828
}
2815
2829
const coercedPrecedence = '' + ( precedence : any ) ;
2816
2830
writeChunk ( destination , arrayInterstitial ) ;
2817
- writeChunk (
2818
- destination ,
2819
- stringToChunk ( escapeJSObjectForInstructionScripts ( coercedPrecedence ) ) ,
2820
- ) ;
2831
+
2832
+ writeStyleResourceObject ( destination , coercedPrecedence ) ;
2821
2833
2822
2834
for ( const propKey in props ) {
2823
2835
if ( hasOwnProperty . call ( props , propKey ) ) {
@@ -2916,13 +2928,7 @@ function writeStyleResourceAttribute(
2916
2928
}
2917
2929
attributeValue = '' + ( value : any ) ;
2918
2930
writeChunk ( destination , arrayInterstitial ) ;
2919
- writeChunk (
2920
- destination ,
2921
- stringToChunk ( escapeJSObjectForInstructionScripts ( attributeName ) ) ,
2922
- ) ;
2931
+ writeStyleResourceObject ( destination , attributeName ) ;
2923
2932
writeChunk ( destination , arrayInterstitial ) ;
2924
- writeChunk (
2925
- destination ,
2926
- stringToChunk ( escapeJSObjectForInstructionScripts ( attributeValue ) ) ,
2927
- ) ;
2933
+ writeStyleResourceObject ( destination , attributeValue ) ;
2928
2934
}
0 commit comments