Skip to content

Commit 0f3ca2b

Browse files
committed
Add nonce support to bootstrap scripts and external runtime (#26738)
Adds support for nonce on `bootstrapScripts`, `bootstrapModules` and the external fizz runtime DiffTrain build for [9545e48](9545e48)
1 parent 59f00e1 commit 0f3ca2b

File tree

7 files changed

+89
-27
lines changed

7 files changed

+89
-27
lines changed

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
b12bea62d9cfd9a925f28cb2c93daeda3865a64e
1+
9545e4810c2dc8922f575b6d8f726503a7345d0c

compiled/facebook-www/ReactDOMServer-dev.classic.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ if (__DEV__) {
1919
var React = require("react");
2020
var ReactDOM = require("react-dom");
2121

22-
var ReactVersion = "18.3.0-www-classic-40ef305a";
22+
var ReactVersion = "18.3.0-www-classic-b5ced452";
2323

2424
// This refers to a WWW module.
2525
var warningWWW = require("warning");
@@ -2368,6 +2368,7 @@ var startInlineScript = stringToPrecomputedChunk("<script>");
23682368
var endInlineScript = stringToPrecomputedChunk("</script>");
23692369
var startScriptSrc = stringToPrecomputedChunk('<script src="');
23702370
var startModuleSrc = stringToPrecomputedChunk('<script type="module" src="');
2371+
var scriptNonce = stringToPrecomputedChunk('" nonce="');
23712372
var scriptIntegirty = stringToPrecomputedChunk('" integrity="');
23722373
var endAsyncScript = stringToPrecomputedChunk('" async=""></script>');
23732374
/**
@@ -2451,6 +2452,13 @@ function createResponseState$1(
24512452
stringToChunk(escapeTextForBrowser(src))
24522453
);
24532454

2455+
if (nonce) {
2456+
bootstrapChunks.push(
2457+
scriptNonce,
2458+
stringToChunk(escapeTextForBrowser(nonce))
2459+
);
2460+
}
2461+
24542462
if (integrity) {
24552463
bootstrapChunks.push(
24562464
scriptIntegirty,
@@ -2477,6 +2485,13 @@ function createResponseState$1(
24772485
stringToChunk(escapeTextForBrowser(_src))
24782486
);
24792487

2488+
if (nonce) {
2489+
bootstrapChunks.push(
2490+
scriptNonce,
2491+
stringToChunk(escapeTextForBrowser(nonce))
2492+
);
2493+
}
2494+
24802495
if (_integrity) {
24812496
bootstrapChunks.push(
24822497
scriptIntegirty,
@@ -2506,7 +2521,8 @@ function createResponseState$1(
25062521
preconnectChunks: [],
25072522
preloadChunks: [],
25082523
hoistableChunks: [],
2509-
stylesToHoist: false
2524+
stylesToHoist: false,
2525+
nonce: nonce
25102526
};
25112527
} // Constants for the insertion mode we're currently writing in. We don't encode all HTML5 insertion
25122528
// modes. We only include the variants as they matter for the sake of our purposes.
@@ -6186,7 +6202,7 @@ function writePreamble(
61866202
var _responseState$extern = responseState.externalRuntimeConfig,
61876203
src = _responseState$extern.src,
61886204
integrity = _responseState$extern.integrity;
6189-
internalPreinitScript(resources, src, integrity);
6205+
internalPreinitScript(resources, src, integrity, responseState.nonce);
61906206
}
61916207

61926208
var htmlChunks = responseState.htmlChunks;
@@ -7412,7 +7428,7 @@ function preinit(href, options) {
74127428
// conform to the types because no user input is being passed in. It also assumes that it is being called as
74137429
// part of a work or flush loop and therefore does not need to request Fizz to flush Resources.
74147430

7415-
function internalPreinitScript(resources, src, integrity) {
7431+
function internalPreinitScript(resources, src, integrity, nonce) {
74167432
var key = getResourceKey("script", src);
74177433
var resource = resources.scriptsMap.get(key);
74187434

@@ -7428,7 +7444,8 @@ function internalPreinitScript(resources, src, integrity) {
74287444
pushScriptImpl(resource.chunks, {
74297445
async: true,
74307446
src: src,
7431-
integrity: integrity
7447+
integrity: integrity,
7448+
nonce: nonce
74327449
});
74337450
}
74347451

@@ -7618,6 +7635,7 @@ function createResponseState(
76187635
preloadChunks: responseState.preloadChunks,
76197636
hoistableChunks: responseState.hoistableChunks,
76207637
stylesToHoist: responseState.stylesToHoist,
7638+
nonce: responseState.nonce,
76217639
// This is an extra field for the legacy renderer
76227640
generateStaticMarkup: generateStaticMarkup
76237641
};

compiled/facebook-www/ReactDOMServer-dev.modern.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ if (__DEV__) {
1919
var React = require("react");
2020
var ReactDOM = require("react-dom");
2121

22-
var ReactVersion = "18.3.0-www-modern-b7ba1a13";
22+
var ReactVersion = "18.3.0-www-modern-ccf9e22e";
2323

2424
// This refers to a WWW module.
2525
var warningWWW = require("warning");
@@ -2368,6 +2368,7 @@ var startInlineScript = stringToPrecomputedChunk("<script>");
23682368
var endInlineScript = stringToPrecomputedChunk("</script>");
23692369
var startScriptSrc = stringToPrecomputedChunk('<script src="');
23702370
var startModuleSrc = stringToPrecomputedChunk('<script type="module" src="');
2371+
var scriptNonce = stringToPrecomputedChunk('" nonce="');
23712372
var scriptIntegirty = stringToPrecomputedChunk('" integrity="');
23722373
var endAsyncScript = stringToPrecomputedChunk('" async=""></script>');
23732374
/**
@@ -2451,6 +2452,13 @@ function createResponseState$1(
24512452
stringToChunk(escapeTextForBrowser(src))
24522453
);
24532454

2455+
if (nonce) {
2456+
bootstrapChunks.push(
2457+
scriptNonce,
2458+
stringToChunk(escapeTextForBrowser(nonce))
2459+
);
2460+
}
2461+
24542462
if (integrity) {
24552463
bootstrapChunks.push(
24562464
scriptIntegirty,
@@ -2477,6 +2485,13 @@ function createResponseState$1(
24772485
stringToChunk(escapeTextForBrowser(_src))
24782486
);
24792487

2488+
if (nonce) {
2489+
bootstrapChunks.push(
2490+
scriptNonce,
2491+
stringToChunk(escapeTextForBrowser(nonce))
2492+
);
2493+
}
2494+
24802495
if (_integrity) {
24812496
bootstrapChunks.push(
24822497
scriptIntegirty,
@@ -2506,7 +2521,8 @@ function createResponseState$1(
25062521
preconnectChunks: [],
25072522
preloadChunks: [],
25082523
hoistableChunks: [],
2509-
stylesToHoist: false
2524+
stylesToHoist: false,
2525+
nonce: nonce
25102526
};
25112527
} // Constants for the insertion mode we're currently writing in. We don't encode all HTML5 insertion
25122528
// modes. We only include the variants as they matter for the sake of our purposes.
@@ -6186,7 +6202,7 @@ function writePreamble(
61866202
var _responseState$extern = responseState.externalRuntimeConfig,
61876203
src = _responseState$extern.src,
61886204
integrity = _responseState$extern.integrity;
6189-
internalPreinitScript(resources, src, integrity);
6205+
internalPreinitScript(resources, src, integrity, responseState.nonce);
61906206
}
61916207

61926208
var htmlChunks = responseState.htmlChunks;
@@ -7412,7 +7428,7 @@ function preinit(href, options) {
74127428
// conform to the types because no user input is being passed in. It also assumes that it is being called as
74137429
// part of a work or flush loop and therefore does not need to request Fizz to flush Resources.
74147430

7415-
function internalPreinitScript(resources, src, integrity) {
7431+
function internalPreinitScript(resources, src, integrity, nonce) {
74167432
var key = getResourceKey("script", src);
74177433
var resource = resources.scriptsMap.get(key);
74187434

@@ -7428,7 +7444,8 @@ function internalPreinitScript(resources, src, integrity) {
74287444
pushScriptImpl(resource.chunks, {
74297445
async: true,
74307446
src: src,
7431-
integrity: integrity
7447+
integrity: integrity,
7448+
nonce: nonce
74327449
});
74337450
}
74347451

@@ -7618,6 +7635,7 @@ function createResponseState(
76187635
preloadChunks: responseState.preloadChunks,
76197636
hoistableChunks: responseState.hoistableChunks,
76207637
stylesToHoist: responseState.stylesToHoist,
7638+
nonce: responseState.nonce,
76217639
// This is an extra field for the legacy renderer
76227640
generateStaticMarkup: generateStaticMarkup
76237641
};

compiled/facebook-www/ReactDOMServer-prod.classic.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,7 +1627,8 @@ function writePreamble(
16271627
internalPreinitScript(
16281628
resources,
16291629
willFlushAllSegments.src,
1630-
willFlushAllSegments.integrity
1630+
willFlushAllSegments.integrity,
1631+
responseState.nonce
16311632
));
16321633
willFlushAllSegments = responseState.htmlChunks;
16331634
var headChunks = responseState.headChunks,
@@ -2078,7 +2079,7 @@ function preinit(href, options) {
20782079
}
20792080
}
20802081
}
2081-
function internalPreinitScript(resources, src, integrity) {
2082+
function internalPreinitScript(resources, src, integrity, nonce) {
20822083
var key = "[script]" + src,
20832084
resource = resources.scriptsMap.get(key);
20842085
resource ||
@@ -2088,7 +2089,8 @@ function internalPreinitScript(resources, src, integrity) {
20882089
pushScriptImpl(resource.chunks, {
20892090
async: !0,
20902091
src: src,
2091-
integrity: integrity
2092+
integrity: integrity,
2093+
nonce: nonce
20922094
}));
20932095
}
20942096
function preloadAsStylePropsFromProps(href, props) {
@@ -2139,6 +2141,7 @@ function createResponseState(
21392141
preloadChunks: [],
21402142
hoistableChunks: [],
21412143
stylesToHoist: !1,
2144+
nonce: void 0,
21422145
generateStaticMarkup: generateStaticMarkup
21432146
};
21442147
}
@@ -3974,4 +3977,4 @@ exports.renderToString = function (children, options) {
39743977
'The server used "renderToString" which does not support Suspense. If you intended for this Suspense boundary to render the fallback content on the server consider throwing an Error somewhere within the Suspense boundary. If you intended to have the server wait for the suspended component please switch to "renderToReadableStream" which supports Suspense on the server'
39753978
);
39763979
};
3977-
exports.version = "18.3.0-www-classic-dcd0808f";
3980+
exports.version = "18.3.0-www-classic-62223ba6";

compiled/facebook-www/ReactDOMServer-prod.modern.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,7 +1625,8 @@ function writePreamble(
16251625
internalPreinitScript(
16261626
resources,
16271627
willFlushAllSegments.src,
1628-
willFlushAllSegments.integrity
1628+
willFlushAllSegments.integrity,
1629+
responseState.nonce
16291630
));
16301631
willFlushAllSegments = responseState.htmlChunks;
16311632
var headChunks = responseState.headChunks,
@@ -2076,7 +2077,7 @@ function preinit(href, options) {
20762077
}
20772078
}
20782079
}
2079-
function internalPreinitScript(resources, src, integrity) {
2080+
function internalPreinitScript(resources, src, integrity, nonce) {
20802081
var key = "[script]" + src,
20812082
resource = resources.scriptsMap.get(key);
20822083
resource ||
@@ -2086,7 +2087,8 @@ function internalPreinitScript(resources, src, integrity) {
20862087
pushScriptImpl(resource.chunks, {
20872088
async: !0,
20882089
src: src,
2089-
integrity: integrity
2090+
integrity: integrity,
2091+
nonce: nonce
20902092
}));
20912093
}
20922094
function preloadAsStylePropsFromProps(href, props) {
@@ -2137,6 +2139,7 @@ function createResponseState(
21372139
preloadChunks: [],
21382140
hoistableChunks: [],
21392141
stylesToHoist: !1,
2142+
nonce: void 0,
21402143
generateStaticMarkup: generateStaticMarkup
21412144
};
21422145
}
@@ -3871,4 +3874,4 @@ exports.renderToString = function (children, options) {
38713874
'The server used "renderToString" which does not support Suspense. If you intended for this Suspense boundary to render the fallback content on the server consider throwing an Error somewhere within the Suspense boundary. If you intended to have the server wait for the suspended component please switch to "renderToReadableStream" which supports Suspense on the server'
38723875
);
38733876
};
3874-
exports.version = "18.3.0-www-modern-9c1f7368";
3877+
exports.version = "18.3.0-www-modern-6b28dd6e";

compiled/facebook-www/ReactDOMServerStreaming-dev.modern.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2365,6 +2365,7 @@ var startInlineScript = stringToPrecomputedChunk("<script>");
23652365
var endInlineScript = stringToPrecomputedChunk("</script>");
23662366
var startScriptSrc = stringToPrecomputedChunk('<script src="');
23672367
var startModuleSrc = stringToPrecomputedChunk('<script type="module" src="');
2368+
var scriptNonce = stringToPrecomputedChunk('" nonce="');
23682369
var scriptIntegirty = stringToPrecomputedChunk('" integrity="');
23692370
var endAsyncScript = stringToPrecomputedChunk('" async=""></script>');
23702371
/**
@@ -2448,6 +2449,13 @@ function createResponseState(
24482449
stringToChunk(escapeTextForBrowser(src))
24492450
);
24502451

2452+
if (nonce) {
2453+
bootstrapChunks.push(
2454+
scriptNonce,
2455+
stringToChunk(escapeTextForBrowser(nonce))
2456+
);
2457+
}
2458+
24512459
if (integrity) {
24522460
bootstrapChunks.push(
24532461
scriptIntegirty,
@@ -2474,6 +2482,13 @@ function createResponseState(
24742482
stringToChunk(escapeTextForBrowser(_src))
24752483
);
24762484

2485+
if (nonce) {
2486+
bootstrapChunks.push(
2487+
scriptNonce,
2488+
stringToChunk(escapeTextForBrowser(nonce))
2489+
);
2490+
}
2491+
24772492
if (_integrity) {
24782493
bootstrapChunks.push(
24792494
scriptIntegirty,
@@ -2503,7 +2518,8 @@ function createResponseState(
25032518
preconnectChunks: [],
25042519
preloadChunks: [],
25052520
hoistableChunks: [],
2506-
stylesToHoist: false
2521+
stylesToHoist: false,
2522+
nonce: nonce
25072523
};
25082524
} // Constants for the insertion mode we're currently writing in. We don't encode all HTML5 insertion
25092525
// modes. We only include the variants as they matter for the sake of our purposes.
@@ -6193,7 +6209,7 @@ function writePreamble(
61936209
var _responseState$extern = responseState.externalRuntimeConfig,
61946210
src = _responseState$extern.src,
61956211
integrity = _responseState$extern.integrity;
6196-
internalPreinitScript(resources, src, integrity);
6212+
internalPreinitScript(resources, src, integrity, responseState.nonce);
61976213
}
61986214

61996215
var htmlChunks = responseState.htmlChunks;
@@ -7419,7 +7435,7 @@ function preinit(href, options) {
74197435
// conform to the types because no user input is being passed in. It also assumes that it is being called as
74207436
// part of a work or flush loop and therefore does not need to request Fizz to flush Resources.
74217437

7422-
function internalPreinitScript(resources, src, integrity) {
7438+
function internalPreinitScript(resources, src, integrity, nonce) {
74237439
var key = getResourceKey("script", src);
74247440
var resource = resources.scriptsMap.get(key);
74257441

@@ -7435,7 +7451,8 @@ function internalPreinitScript(resources, src, integrity) {
74357451
pushScriptImpl(resource.chunks, {
74367452
async: true,
74377453
src: src,
7438-
integrity: integrity
7454+
integrity: integrity,
7455+
nonce: nonce
74397456
});
74407457
}
74417458

compiled/facebook-www/ReactDOMServerStreaming-prod.modern.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,7 +1656,8 @@ function writePreamble(
16561656
internalPreinitScript(
16571657
resources,
16581658
willFlushAllSegments.src,
1659-
willFlushAllSegments.integrity
1659+
willFlushAllSegments.integrity,
1660+
responseState.nonce
16601661
));
16611662
willFlushAllSegments = responseState.htmlChunks;
16621663
var headChunks = responseState.headChunks,
@@ -2128,7 +2129,7 @@ function preinit(href, options) {
21282129
}
21292130
}
21302131
}
2131-
function internalPreinitScript(resources, src, integrity) {
2132+
function internalPreinitScript(resources, src, integrity, nonce) {
21322133
var key = "[script]" + src,
21332134
resource = resources.scriptsMap.get(key);
21342135
resource ||
@@ -2138,7 +2139,8 @@ function internalPreinitScript(resources, src, integrity) {
21382139
pushScriptImpl(resource.chunks, {
21392140
async: !0,
21402141
src: src,
2141-
integrity: integrity
2142+
integrity: integrity,
2143+
nonce: nonce
21422144
}));
21432145
}
21442146
function preloadAsStylePropsFromProps(href, props) {
@@ -3878,7 +3880,8 @@ exports.renderToStream = function (children, options) {
38783880
preconnectChunks: [],
38793881
preloadChunks: [],
38803882
hoistableChunks: [],
3881-
stylesToHoist: !1
3883+
stylesToHoist: !1,
3884+
nonce: void 0
38823885
};
38833886
bootstrapModules = createFormatContext(0, null, !1);
38843887
externalRuntimeDesc = options ? options.progressiveChunkSize : void 0;

0 commit comments

Comments
 (0)