Skip to content

Commit

Permalink
[Float][Fizz] add crossOrigin support for preloading bootstrap script…
Browse files Browse the repository at this point in the history
…s 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
  • Loading branch information
gnoff authored Jun 13, 2023
1 parent 7ed6084 commit a7bf5ba
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
8 changes: 6 additions & 2 deletions packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ export function createResponseState(
? 'use-credentials'
: '';

preloadBootstrapScript(resources, src, nonce, integrity);
preloadBootstrapScript(resources, src, nonce, integrity, crossOrigin);

bootstrapChunks.push(
startScriptSrc,
Expand Down Expand Up @@ -322,7 +322,7 @@ export function createResponseState(
? 'use-credentials'
: '';

preloadBootstrapModule(resources, src, nonce, integrity);
preloadBootstrapModule(resources, src, nonce, integrity, crossOrigin);

bootstrapChunks.push(
startModuleSrc,
Expand Down Expand Up @@ -5425,6 +5425,7 @@ function preloadBootstrapScript(
src: string,
nonce: ?string,
integrity: ?string,
crossOrigin: ?string,
): void {
const key = getResourceKey('script', src);
if (__DEV__) {
Expand All @@ -5444,6 +5445,7 @@ function preloadBootstrapScript(
as: 'script',
nonce,
integrity,
crossOrigin,
};
const resource: PreloadResource = {
type: 'preload',
Expand All @@ -5465,6 +5467,7 @@ function preloadBootstrapModule(
src: string,
nonce: ?string,
integrity: ?string,
crossOrigin: ?string,
): void {
const key = getResourceKey('script', src);
if (__DEV__) {
Expand All @@ -5483,6 +5486,7 @@ function preloadBootstrapModule(
href: src,
nonce,
integrity,
crossOrigin,
};
const resource: PreloadResource = {
type: 'preload',
Expand Down
14 changes: 13 additions & 1 deletion packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3865,7 +3865,19 @@ describe('ReactDOMFizzServer', () => {

expect(getVisibleChildren(document)).toEqual(
<html>
<head />
<head>
<link rel="preload" href="foo" as="script" />
<link rel="preload" href="bar" as="script" />
<link rel="preload" href="baz" as="script" crossorigin="" />
<link rel="preload" href="qux" as="script" crossorigin="" />
<link rel="modulepreload" href="quux" />
<link rel="modulepreload" href="corge" />
<link
rel="modulepreload"
href="grault"
crossorigin="use-credentials"
/>
</head>
<body>
<div>hello world</div>
</body>
Expand Down

0 comments on commit a7bf5ba

Please sign in to comment.