Skip to content

Commit

Permalink
[Fiber][Float] preinitialized stylesheets should support integrity op…
Browse files Browse the repository at this point in the history
…tion (#26881)

preinitialized stylesheets did not render the integrity option on the
client implementation of Float. This was an oversight.
  • Loading branch information
gnoff committed May 31, 2023
1 parent 1cea384 commit e1e68b9
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2394,6 +2394,7 @@ function stylesheetPropsFromPreinitOptions(
href,
'data-precedence': precedence,
crossOrigin: options.crossOrigin,
integrity: options.integrity,
};
}

Expand Down
65 changes: 65 additions & 0 deletions packages/react-dom/src/__tests__/ReactDOMFloat-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4409,6 +4409,71 @@ body {
</html>,
);
});

it('accepts an `integrity` option for `as: "style"`', async () => {
function Component({src, hash}) {
ReactDOM.preinit(src, {as: 'style', integrity: hash});
return 'hello';
}

await act(() => {
renderToPipeableStream(
<html>
<body>
<Component src="foo" hash="foo hash" />
</body>
</html>,
{
nonce: 'R4nD0m',
},
).pipe(writable);
});

expect(getMeaningfulChildren(document)).toEqual(
<html>
<head>
<link
rel="stylesheet"
href="foo"
integrity="foo hash"
data-precedence="default"
/>
</head>
<body>hello</body>
</html>,
);

await clientAct(() => {
ReactDOMClient.hydrateRoot(
document,
<html>
<body>
<Component src="bar" hash="bar hash" />
</body>
</html>,
);
});

expect(getMeaningfulChildren(document)).toEqual(
<html>
<head>
<link
rel="stylesheet"
href="foo"
integrity="foo hash"
data-precedence="default"
/>
<link
rel="stylesheet"
href="bar"
integrity="bar hash"
data-precedence="default"
/>
</head>
<body>hello</body>
</html>,
);
});
});

describe('Stylesheet Resources', () => {
Expand Down

0 comments on commit e1e68b9

Please sign in to comment.