[Float][Fizz] add crossOrigin support for preloading bootstrap scripts and bootstrap modules (#26942)
The recently merged support for crossorigin in bootstrap scripts did not implement the functionality for preloading. This adds it see #26844
Josh Story committed
Jun 13, 2023 at 13:59 UTC
a7bf5ba614c6ddbd1eb3057c71f72efd1b6c21a9
2 files changed
+19
-3
packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js
+6
-2
@@ -281,7 +281,7 @@ export function createResponseState(
281
? 'use-credentials'
282
: '';
283
284
- preloadBootstrapScript(resources, src, nonce, integrity);
284
+ preloadBootstrapScript(resources, src, nonce, integrity, crossOrigin);
285
286
bootstrapChunks.push(
287
startScriptSrc,
@@ -322,7 +322,7 @@ export function createResponseState(
322
? 'use-credentials'
323
: '';
324
325
- preloadBootstrapModule(resources, src, nonce, integrity);
325
+ preloadBootstrapModule(resources, src, nonce, integrity, crossOrigin);
326
327
bootstrapChunks.push(
328
startModuleSrc,
@@ -5425,6 +5425,7 @@ function preloadBootstrapScript(
5425
src: string,
5426
nonce: ?string,
5427
integrity: ?string,
5428
+ crossOrigin: ?string,
5429
): void {
5430
const key = getResourceKey('script', src);
5431
if (__DEV__) {
@@ -5444,6 +5445,7 @@ function preloadBootstrapScript(
5445
as: 'script',
5446
nonce,
5447
integrity,
5448
+ crossOrigin,
5449
};
5450
const resource: PreloadResource = {
5451
type: 'preload',
@@ -5465,6 +5467,7 @@ function preloadBootstrapModule(
5467
src: string,
5468
nonce: ?string,
5469
integrity: ?string,
5470
+ crossOrigin: ?string,
5471
): void {
5472
const key = getResourceKey('script', src);
5473
if (__DEV__) {
@@ -5483,6 +5486,7 @@ function preloadBootstrapModule(
5486
href: src,
5487
nonce,
5488
integrity,
5489
+ crossOrigin,
5490
};
5491
const resource: PreloadResource = {
5492
type: 'preload',
packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js
+13
-1
@@ -3865,7 +3865,19 @@ describe('ReactDOMFizzServer', () => {
3865
3866
expect(getVisibleChildren(document)).toEqual(
3867
<html>
3868
- <head />
3868
+ <head>
3869
+ <link rel="preload" href="foo" as="script" />
3870
+ <link rel="preload" href="bar" as="script" />
3871
+ <link rel="preload" href="baz" as="script" crossorigin="" />
3872
+ <link rel="preload" href="qux" as="script" crossorigin="" />
3873
+ <link rel="modulepreload" href="quux" />
3874
+ <link rel="modulepreload" href="corge" />
3875
+ <link
3876
+ rel="modulepreload"
3877
+ href="grault"
3878
+ crossorigin="use-credentials"
3879
+ />
3880
+ </head>
3881
<body>
3882
<div>hello world</div>
3883
</body>