3545
);
3546
});
3547
3548
+ it('uses imageSrcSet and imageSizes when keying image preloads', async () => {
3549
+ function App({isClient}) {
3550
+ // Will key off href in absense of imageSrcSet
3551
+ ReactDOM.preload('foo', {as: 'image'});
3552
+ ReactDOM.preload('foo', {as: 'image'});
3553
+
3554
+ // Will key off imageSrcSet + imageSizes
3555
+ ReactDOM.preload('foo', {as: 'image', imageSrcSet: 'fooset'});
3556
+ ReactDOM.preload('foo2', {as: 'image', imageSrcSet: 'fooset'});
3557
+
3558
+ // Will key off imageSrcSet + imageSizes
3559
+ ReactDOM.preload('foo', {
3560
+ as: 'image',
3561
+ imageSrcSet: 'fooset',
3562
+ imageSizes: 'foosizes',
3563
+ });
3564
+ ReactDOM.preload('foo2', {
3565
+ as: 'image',
3566
+ imageSrcSet: 'fooset',
3567
+ imageSizes: 'foosizes',
3568
+ });
3569
+
3570
+ // Will key off href in absense of imageSrcSet, imageSizes is ignored. these should match the
3571
+ // first preloads not not emit a new preload tag
3572
+ ReactDOM.preload('foo', {as: 'image', imageSizes: 'foosizes'});
3573
+ ReactDOM.preload('foo', {as: 'image', imageSizes: 'foosizes'});
3574
+
3575
+ // These preloads are for something that isn't an image
3576
+ // They should all key off the href
3577
+ ReactDOM.preload('bar', {as: 'somethingelse'});
3578
+ ReactDOM.preload('bar', {
3579
+ as: 'somethingelse',
3580
+ imageSrcSet: 'makes no sense',
3581
+ });
3582
+ ReactDOM.preload('bar', {
3583
+ as: 'somethingelse',
3584
+ imageSrcSet: 'makes no sense',
3585
+ imageSizes: 'makes no sense',
3586
+ });
3587
+
3588
+ if (isClient) {
3589
+ // Will key off href in absense of imageSrcSet
3590
+ ReactDOM.preload('client', {as: 'image'});
3591
+ ReactDOM.preload('client', {as: 'image'});
3592
+
3593
+ // Will key off imageSrcSet + imageSizes
3594
+ ReactDOM.preload('client', {as: 'image', imageSrcSet: 'clientset'});
3595
+ ReactDOM.preload('client2', {as: 'image', imageSrcSet: 'clientset'});
3596
+
3597
+ // Will key off imageSrcSet + imageSizes
3598
+ ReactDOM.preload('client', {
3599
+ as: 'image',
3600
+ imageSrcSet: 'clientset',
3601
+ imageSizes: 'clientsizes',
3602
+ });
3603
+ ReactDOM.preload('client2', {
3604
+ as: 'image',
3605
+ imageSrcSet: 'clientset',
3606
+ imageSizes: 'clientsizes',
3607
+ });
3608
+
3609
+ // Will key off href in absense of imageSrcSet, imageSizes is ignored. these should match the
3610
+ // first preloads not not emit a new preload tag
3611
+ ReactDOM.preload('client', {as: 'image', imageSizes: 'clientsizes'});
3612
+ ReactDOM.preload('client', {as: 'image', imageSizes: 'clientsizes'});
3613
+ }
3614
+
3615
+ return (
3616
+ <html>
3617
+ <body>hello</body>
3618
+ </html>
3619
+ );
3620
+ }
3621
+
3622
+ await act(() => {
3623
+ renderToPipeableStream(<App />).pipe(writable);
3624
+ });
3625
+ expect(getMeaningfulChildren(document)).toEqual(
3626
+ <html>
3627
+ <head>
3628
+ <link rel="preload" as="image" href="foo" />
3629
+ <link rel="preload" as="image" imagesrcset="fooset" />
3630
+ <link
3631
+ rel="preload"
3632
+ as="image"
3633
+ imagesrcset="fooset"
3634
+ imagesizes="foosizes"
3635
+ />
3636
+ <link rel="preload" as="somethingelse" href="bar" />
3637
+ </head>
3638
+ <body>hello</body>
3639
+ </html>,
3640
+ );
3641
+
3642
+ const root = ReactDOMClient.hydrateRoot(document, <App />);
3643
+ await waitForAll([]);
3644
+ expect(getMeaningfulChildren(document)).toEqual(
3645
+ <html>
3646
+ <head>
3647
+ <link rel="preload" as="image" href="foo" />
3648
+ <link rel="preload" as="image" imagesrcset="fooset" />
3649
+ <link
3650
+ rel="preload"
3651
+ as="image"
3652
+ imagesrcset="fooset"
3653
+ imagesizes="foosizes"
3654
+ />
3655
+ <link rel="preload" as="somethingelse" href="bar" />
3656
+ </head>
3657
+ <body>hello</body>
3658
+ </html>,
3659
+ );
3660
+
3661
+ root.render(<App isClient={true} />);
3662
+ await waitForAll([]);
3663
+ expect(getMeaningfulChildren(document)).toEqual(
3664
+ <html>
3665
+ <head>
3666
+ <link rel="preload" as="image" href="foo" />
3667
+ <link rel="preload" as="image" imagesrcset="fooset" />
3668
+ <link
3669
+ rel="preload"
3670
+ as="image"
3671
+ imagesrcset="fooset"
3672
+ imagesizes="foosizes"
3673
+ />
3674
+ <link rel="preload" as="somethingelse" href="bar" />
3675
+ <link rel="preload" as="image" href="client" />
3676
+ <link rel="preload" as="image" imagesrcset="clientset" />
3677
+ <link
3678
+ rel="preload"
3679
+ as="image"
3680
+ imagesrcset="clientset"
3681
+ imagesizes="clientsizes"
3682
+ />
3683
+ </head>
3684
+ <body>hello</body>
3685
+ </html>,
3686
+ );
3687
+ });
3688
+
3689
describe('ReactDOM.prefetchDNS(href)', () => {
3690
it('creates a dns-prefetch resource when called', async () => {
3691
function App({url}) {
3975
renderToPipeableStream(<App />).pipe(writable);
3976
});
3977
}).toErrorDev([
3837
- 'ReactDOM.preload(): Expected the `href` argument (first) to be a non-empty string but encountered `undefined` instead.',
3838
- 'ReactDOM.preload(): Expected the `href` argument (first) to be a non-empty string but encountered an empty string instead.',
3839
- 'ReactDOM.preload(): Expected the `options` argument (second) to be an object with an `as` property describing the type of resource to be preloaded but encountered `null` instead.',
3840
- 'ReactDOM.preload(): Expected the `as` property in the `options` argument (second) to contain a string value describing the type of resource to be preloaded but encountered `undefined` instead. Values that are valid in for the `as` attribute of a `<link rel="preload" as="..." />` tag are valid here.',
3978
+ 'ReactDOM.preload(): Expected two arguments, a non-empty `href` string and an `options` object with an `as` property valid for a `<link rel="preload" as="..." />` tag. The `href` argument encountered was `undefined`. The `options` argument encountered was `undefined`.',
3979
+ 'ReactDOM.preload(): Expected two arguments, a non-empty `href` string and an `options` object with an `as` property valid for a `<link rel="preload" as="..." />` tag. The `href` argument encountered was an empty string. The `options` argument encountered was `undefined`.',
3980
+ 'ReactDOM.preload(): Expected two arguments, a non-empty `href` string and an `options` object with an `as` property valid for a `<link rel="preload" as="..." />` tag. The `options` argument encountered was `null`.',
3981
+ 'ReactDOM.preload(): Expected two arguments, a non-empty `href` string and an `options` object with an `as` property valid for a `<link rel="preload" as="..." />` tag. The `as` option encountered was `undefined`.',
3982
]);
3983
});
3984