Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add referrerPolicy option to ReactDOM.preload() #27096

Merged
merged 2 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2284,6 +2284,7 @@ function preloadPropsFromPreloadOptions(
fetchPriority: options.fetchPriority,
imageSrcSet: options.imageSrcSet,
imageSizes: options.imageSizes,
referrerPolicy: options.referrerPolicy,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5564,6 +5564,7 @@ function preloadPropsFromPreloadOptions(
fetchPriority: options.fetchPriority,
imageSrcSet: options.imageSrcSet,
imageSizes: options.imageSizes,
referrerPolicy: options.referrerPolicy,
};
}

Expand Down
28 changes: 28 additions & 0 deletions packages/react-dom/src/__tests__/ReactDOMFloat-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3585,6 +3585,13 @@ body {
imageSizes: 'makes no sense',
});

ReactDOM.preload('rp', {
as: 'image',
imageSrcSet: 'rpsrcset',
imageSizes: 'rpsizes',
referrerPolicy: 'no-referrer',
});

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just make a new test. The preload calls in this test are designed to demonstrate the keying behavior and throwing the ancillary rp preload here is going to maybe be confusing in the future. There is probably already a more generic test acutally that you can just add referrer policy to and just modify the assertions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created a new test in 24e2703

if (isClient) {
// Will key off href in absense of imageSrcSet
ReactDOM.preload('client', {as: 'image'});
Expand Down Expand Up @@ -3634,6 +3641,13 @@ body {
imagesizes="foosizes"
/>
<link rel="preload" as="somethingelse" href="bar" />
<link
rel="preload"
as="image"
imagesrcset="rpsrcset"
imagesizes="rpsizes"
referrerpolicy="no-referrer"
/>
</head>
<body>hello</body>
</html>,
Expand All @@ -3653,6 +3667,13 @@ body {
imagesizes="foosizes"
/>
<link rel="preload" as="somethingelse" href="bar" />
<link
rel="preload"
as="image"
imagesrcset="rpsrcset"
imagesizes="rpsizes"
referrerpolicy="no-referrer"
/>
</head>
<body>hello</body>
</html>,
Expand All @@ -3672,6 +3693,13 @@ body {
imagesizes="foosizes"
/>
<link rel="preload" as="somethingelse" href="bar" />
<link
rel="preload"
as="image"
imagesrcset="rpsrcset"
imagesizes="rpsizes"
referrerpolicy="no-referrer"
/>
<link rel="preload" as="image" href="client" />
<link rel="preload" as="image" imagesrcset="clientset" />
<link
Expand Down
1 change: 1 addition & 0 deletions packages/react-dom/src/shared/ReactDOMTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type PreloadOptions = {
fetchPriority?: 'high' | 'low' | 'auto',
imageSrcSet?: string,
imageSizes?: string,
referrerPolicy?: string,
};
export type PreinitOptions = {
as: string,
Expand Down