Skip to content

Commit a7cce7b

Browse files
[Fizz] Preserve referrerPolicy in image preload headers (react#36803)
1 parent ad78e25 commit a7cce7b

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3405,7 +3405,7 @@ function pushImg(
34053405
nonce: props.nonce,
34063406
type: props.type,
34073407
fetchPriority: props.fetchPriority,
3408-
referrerPolicy: props.refererPolicy,
3408+
referrerPolicy: props.referrerPolicy,
34093409
})),
34103410
// We always consume the header length since once we find one header that doesn't fit
34113411
// we assume all the rest won't as well. This is to avoid getting into a situation

packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3934,6 +3934,35 @@ describe('ReactDOMFizzServer', () => {
39343934
});
39353935
});
39363936

3937+
it('preserves referrerPolicy for image preload headers', async () => {
3938+
let headers = null;
3939+
function onHeaders(x) {
3940+
headers = x;
3941+
}
3942+
3943+
function App() {
3944+
return (
3945+
<html>
3946+
<body>
3947+
<img
3948+
src="image-with-referrer-policy"
3949+
fetchPriority="high"
3950+
referrerPolicy="no-referrer"
3951+
/>
3952+
</body>
3953+
</html>
3954+
);
3955+
}
3956+
3957+
await act(() => {
3958+
renderToPipeableStream(<App />, {onHeaders});
3959+
});
3960+
3961+
expect(headers).toEqual({
3962+
Link: `<image-with-referrer-policy>; rel=preload; as="image"; fetchpriority="high"; referrerpolicy="no-referrer"`,
3963+
});
3964+
});
3965+
39373966
it('emits nothing for headers if you pipe before work begins', async () => {
39383967
let headers = null;
39393968
function onHeaders(x) {

0 commit comments

Comments
 (0)