Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
gnoff committed Sep 20, 2022
1 parent 7a67594 commit 950ef9c
Show file tree
Hide file tree
Showing 3 changed files with 372 additions and 63 deletions.
49 changes: 49 additions & 0 deletions packages/react-dom/src/__tests__/ReactDOMFloat-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,55 @@ describe('ReactDOMFizzServer', () => {
</html>,
);
});

it('inserts a preload resource when called in a layout effect', async () => {
function App() {
React.useLayoutEffect(() => {
console.log('calling preload inside useEffect');
ReactDOM.preload('foo', {as: 'style'});
}, []);
return 'foobar';
}
const root = ReactDOMClient.createRoot(container);
root.render(<App />);
expect(Scheduler).toFlushWithoutYielding();

console.log('document', document.documentElement.outerHTML);
expect(getVisibleChildren(document)).toEqual(
<html>
<head>
<link rel="preload" as="style" href="foo" />
</head>
<body>
<div id="container">foobar</div>
</body>
</html>,
);
});

fit('inserts a preload resource when called in a passive effect', async () => {
function App() {
React.useEffect(() => {
ReactDOM.preload('foo', {as: 'style'});
}, []);
return 'foobar';
}
const root = ReactDOMClient.createRoot(container);
root.render(<App />);
expect(Scheduler).toFlushWithoutYielding();

console.log('document', document.documentElement.outerHTML);
expect(getVisibleChildren(document)).toEqual(
<html>
<head>
<link rel="preload" as="style" href="foo" />
</head>
<body>
<div id="container">foobar</div>
</body>
</html>,
);
});
});

describe('style resources', () => {
Expand Down
Loading

0 comments on commit 950ef9c

Please sign in to comment.