Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .changeset/strip-image-preload-imagesrcset.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@react-email/render": patch
---

Strip image preload links that carry `imagesrcset` or `imagesizes` without `as="image"`, so React-injected responsive-image hints no longer leak into rendered email HTML.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ describe('stripImagePreloadLinks()', () => {
expect(stripImagePreloadLinks(html)).toBe('<head></head>');
});

it('removes image preloads with imagesrcset or imagesizes when as="image" is omitted', () => {
const html =
'<head><link rel="preload" imagesrcset="logo.png 2x"/><link rel="preload" imagesizes="100vw"/></head>';

expect(stripImagePreloadLinks(html)).toBe('<head></head>');
});

it('keeps user-authored non-image preloads', () => {
const html =
'<head><link rel="preload" as="style" href="styles.css"/><link rel="preload" as="font" href="font.woff2"/></head>';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ export const stripImagePreloadLinks = (html: string): string => {

const isImagePreloadLink = (tag: string): boolean => {
const attributes = parseAttributes(tag);
return attributes.rel === 'preload' && attributes.as === 'image';
return (
attributes.rel === 'preload' &&
(attributes.as === 'image' ||
'imagesrcset' in attributes ||
'imagesizes' in attributes)
);
};

const ATTRIBUTE_PATTERN =
Expand Down