Skip to content

Commit 77c452a

Browse files
gnoffAndyPengc12
authored andcommitted
[Float][Fizz] add crossOrigin support for preloading bootstrap scripts and bootstrap modules (facebook#26942)
The recently merged support for crossorigin in bootstrap scripts did not implement the functionality for preloading. This adds it see facebook#26844
1 parent acc8609 commit 77c452a

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ export function createResponseState(
281281
? 'use-credentials'
282282
: '';
283283

284-
preloadBootstrapScript(resources, src, nonce, integrity);
284+
preloadBootstrapScript(resources, src, nonce, integrity, crossOrigin);
285285

286286
bootstrapChunks.push(
287287
startScriptSrc,
@@ -322,7 +322,7 @@ export function createResponseState(
322322
? 'use-credentials'
323323
: '';
324324

325-
preloadBootstrapModule(resources, src, nonce, integrity);
325+
preloadBootstrapModule(resources, src, nonce, integrity, crossOrigin);
326326

327327
bootstrapChunks.push(
328328
startModuleSrc,
@@ -5425,6 +5425,7 @@ function preloadBootstrapScript(
54255425
src: string,
54265426
nonce: ?string,
54275427
integrity: ?string,
5428+
crossOrigin: ?string,
54285429
): void {
54295430
const key = getResourceKey('script', src);
54305431
if (__DEV__) {
@@ -5444,6 +5445,7 @@ function preloadBootstrapScript(
54445445
as: 'script',
54455446
nonce,
54465447
integrity,
5448+
crossOrigin,
54475449
};
54485450
const resource: PreloadResource = {
54495451
type: 'preload',
@@ -5465,6 +5467,7 @@ function preloadBootstrapModule(
54655467
src: string,
54665468
nonce: ?string,
54675469
integrity: ?string,
5470+
crossOrigin: ?string,
54685471
): void {
54695472
const key = getResourceKey('script', src);
54705473
if (__DEV__) {
@@ -5483,6 +5486,7 @@ function preloadBootstrapModule(
54835486
href: src,
54845487
nonce,
54855488
integrity,
5489+
crossOrigin,
54865490
};
54875491
const resource: PreloadResource = {
54885492
type: 'preload',

packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3865,7 +3865,19 @@ describe('ReactDOMFizzServer', () => {
38653865

38663866
expect(getVisibleChildren(document)).toEqual(
38673867
<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>
38693881
<body>
38703882
<div>hello world</div>
38713883
</body>

0 commit comments

Comments
 (0)