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

[Float] Don't preload images inside <noscript> #28815

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -2762,7 +2762,7 @@ function pushImg(
props: Object,
resumableState: ResumableState,
renderState: RenderState,
pictureTagInScope: boolean,
pictureOrNoScriptTagInScope: boolean,
): null {
const {src, srcSet} = props;
if (
Expand All @@ -2771,7 +2771,7 @@ function pushImg(
(typeof src === 'string' || src == null) &&
(typeof srcSet === 'string' || srcSet == null) &&
props.fetchPriority !== 'low' &&
pictureTagInScope === false &&
pictureOrNoScriptTagInScope === false &&
// We exclude data URIs in src and srcSet since these should not be preloaded
!(
typeof src === 'string' &&
Expand Down Expand Up @@ -3599,7 +3599,7 @@ export function pushStartInstance(
props,
resumableState,
renderState,
!!(formatContext.tagScope & PICTURE_SCOPE),
!!(formatContext.tagScope & (PICTURE_SCOPE | NOSCRIPT_SCOPE)),
);
}
// Omitted close tags
Expand Down
32 changes: 32 additions & 0 deletions packages/react-dom/src/__tests__/ReactDOMFloat-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4261,6 +4261,38 @@ body {
);
});

// Fixes: https://github.com/facebook/react/issues/27910
it('omits preloads for images inside noscript tags', async () => {
function App() {
return (
<html>
<body>
<img src="foo" />
<noscript>
<img src="bar" />
</noscript>
</body>
</html>
);
}

await act(() => {
renderToPipeableStream(<App />).pipe(writable);
});

expect(getMeaningfulChildren(document)).toEqual(
<html>
<head>
<link rel="preload" href="foo" as="image" />
</head>
<body>
<img src="foo" />
<noscript>&lt;img src="bar"&gt;</noscript>
</body>
</html>,
);
});

it('should handle media on image preload', async () => {
function App({isClient}) {
ReactDOM.preload('/server', {
Expand Down