mirror of
https://github.com/hanzoai/react.git
synced 2026-09-24 17:02:27 +00:00
Add referrerPolicy option to ReactDOM.preload() (#27096)
This commit is contained in:
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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}) {
|
||||
|
||||
@@ -18,6 +18,7 @@ export type PreloadOptions = {
|
||||
fetchPriority?: 'high' | 'low' | 'auto',
|
||||
imageSrcSet?: string,
|
||||
imageSizes?: string,
|
||||
referrerPolicy?: string,
|
||||
};
|
||||
export type PreinitOptions = {
|
||||
as: string,
|
||||
|
||||
Reference in New Issue
Block a user