Add referrerPolicy option to ReactDOM.preload() (#27096)

This commit is contained in:
Steven
2023-07-12 14:32:56 -07:00
committed by GitHub
parent 0853cfb79f
commit da9b3aedbb
4 changed files with 88 additions and 0 deletions
@@ -2284,6 +2284,7 @@ function preloadPropsFromPreloadOptions(
fetchPriority: options.fetchPriority,
imageSrcSet: options.imageSrcSet,
imageSizes: options.imageSizes,
referrerPolicy: options.referrerPolicy,
};
}
@@ -5564,6 +5564,7 @@ function preloadPropsFromPreloadOptions(
fetchPriority: options.fetchPriority,
imageSrcSet: options.imageSrcSet,
imageSizes: options.imageSizes,
referrerPolicy: options.referrerPolicy,
};
}
+85
View File
@@ -3686,6 +3686,91 @@ body {
);
});
it('should handle referrerPolicy on image preload', async () => {
function App({isClient}) {
ReactDOM.preload('/server', {
as: 'image',
imageSrcSet: '/server',
imageSizes: '100vw',
referrerPolicy: 'no-referrer',
});
if (isClient) {
ReactDOM.preload('/client', {
as: 'image',
imageSrcSet: '/client',
imageSizes: '100vw',
referrerPolicy: 'no-referrer',
});
}
return (
<html>
<body>hello</body>
</html>
);
}
await act(() => {
renderToPipeableStream(<App />).pipe(writable);
});
expect(getMeaningfulChildren(document)).toEqual(
<html>
<head>
<link
rel="preload"
as="image"
imagesrcset="/server"
imagesizes="100vw"
referrerpolicy="no-referrer"
/>
</head>
<body>hello</body>
</html>,
);
const root = ReactDOMClient.hydrateRoot(document, <App />);
await waitForAll([]);
expect(getMeaningfulChildren(document)).toEqual(
<html>
<head>
<link
rel="preload"
as="image"
imagesrcset="/server"
imagesizes="100vw"
referrerpolicy="no-referrer"
/>
</head>
<body>hello</body>
</html>,
);
root.render(<App isClient={true} />);
await waitForAll([]);
expect(getMeaningfulChildren(document)).toEqual(
<html>
<head>
<link
rel="preload"
as="image"
imagesrcset="/server"
imagesizes="100vw"
referrerpolicy="no-referrer"
/>
<link
rel="preload"
as="image"
imagesrcset="/client"
imagesizes="100vw"
referrerpolicy="no-referrer"
/>
</head>
<body>hello</body>
</html>,
);
});
describe('ReactDOM.prefetchDNS(href)', () => {
it('creates a dns-prefetch resource when called', async () => {
function App({url}) {
+1
View File
@@ -18,6 +18,7 @@ export type PreloadOptions = {
fetchPriority?: 'high' | 'low' | 'auto',
imageSrcSet?: string,
imageSizes?: string,
referrerPolicy?: string,
};
export type PreinitOptions = {
as: string,