Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adds a test to cover the case where you preload a stylesheet but then…
… render a styletag with the href using precedence. This is probably done as a mistake (accidentally using the same href) but if you are going to inline on your own then you should also take care not to preload
  • Loading branch information
gnoff committed Sep 26, 2023
commit e78140c7080e32b7fd81e5131b3baffac944d5e6
37 changes: 37 additions & 0 deletions packages/react-dom/src/__tests__/ReactDOMFloat-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4119,6 +4119,43 @@ body {
);
});

it('should warn if you preload a stylesheet and then render a style tag with the same href', async () => {
const style = 'body { color: red; }';
function App() {
ReactDOM.preload('foo', {as: 'style'});
return (
<html>
<body>
hello
<style precedence="default" href="foo">
{style}
</style>
</body>
</html>
);
}

await expect(async () => {
await act(() => {
renderToPipeableStream(<App />).pipe(writable);
});
}).toErrorDev([
'React encountered a hoistable style tag for the same href as a preload: "foo". When using a style tag to inline styles you should not also preload it as a stylsheet.',
]);

expect(getMeaningfulChildren(document)).toEqual(
<html>
<head>
<style data-precedence="default" data-href="foo">
{style}
</style>
<link rel="preload" as="style" href="foo" />
</head>
<body>hello</body>
</html>,
);
});

it('should preload only once even if you discover a stylesheet, script, or moduleScript late', async () => {
function App() {
// We start with preinitializing some resources first
Expand Down