@@ -281,6 +281,55 @@ describe('ReactDOMFizzServer', () => {
281281 </ html > ,
282282 ) ;
283283 } ) ;
284+
285+ it ( 'inserts a preload resource when called in a layout effect' , async ( ) => {
286+ function App ( ) {
287+ React . useLayoutEffect ( ( ) => {
288+ console . log ( 'calling preload inside useEffect' ) ;
289+ ReactDOM . preload ( 'foo' , { as : 'style' } ) ;
290+ } , [ ] ) ;
291+ return 'foobar' ;
292+ }
293+ const root = ReactDOMClient . createRoot ( container ) ;
294+ root . render ( < App /> ) ;
295+ expect ( Scheduler ) . toFlushWithoutYielding ( ) ;
296+
297+ console . log ( 'document' , document . documentElement . outerHTML ) ;
298+ expect ( getVisibleChildren ( document ) ) . toEqual (
299+ < html >
300+ < head >
301+ < link rel = "preload" as = "style" href = "foo" />
302+ </ head >
303+ < body >
304+ < div id = "container" > foobar</ div >
305+ </ body >
306+ </ html > ,
307+ ) ;
308+ } ) ;
309+
310+ fit ( 'inserts a preload resource when called in a passive effect' , async ( ) => {
311+ function App ( ) {
312+ React . useEffect ( ( ) => {
313+ ReactDOM . preload ( 'foo' , { as : 'style' } ) ;
314+ } , [ ] ) ;
315+ return 'foobar' ;
316+ }
317+ const root = ReactDOMClient . createRoot ( container ) ;
318+ root . render ( < App /> ) ;
319+ expect ( Scheduler ) . toFlushWithoutYielding ( ) ;
320+
321+ console . log ( 'document' , document . documentElement . outerHTML ) ;
322+ expect ( getVisibleChildren ( document ) ) . toEqual (
323+ < html >
324+ < head >
325+ < link rel = "preload" as = "style" href = "foo" />
326+ </ head >
327+ < body >
328+ < div id = "container" > foobar</ div >
329+ </ body >
330+ </ html > ,
331+ ) ;
332+ } ) ;
284333 } ) ;
285334
286335 describe ( 'style resources' , ( ) => {
0 commit comments