react-email icon indicating copy to clipboard operation
react-email copied to clipboard

render: image preload links with imagesrcset or imagesizes survive stripping when as=image is omitted

Open Tyagiquamar opened this issue 2 months ago • 1 comments

React 19 can emit image preload hints that carry imagesrcset/imagesizes without an as=image attribute, e.g.:

stripImagePreloadLinks in packages/render/src/shared/utils/strip-image-preload-links.ts (verified on canary) only removes preloads with as=image, so these tags survive into the rendered email HTML even though email clients ignore link rel=preload.

Expected: preload links carrying imagesrcset or imagesizes are image preloads and should be stripped just like as=image ones. Non-image preloads (e.g. as=style, as=font) and other link tags must be kept.

Tyagiquamar avatar Sep 23 '26 05:09 Tyagiquamar

Thanks for opening an issue first and for the PR.

We tried to reproduce this but couldn't. On React 18.3.1, 19.2.4 and the 19.3 canary, every image preload that React emits has as="image". We tested these cases with renderToString, renderToStaticMarkup and renderToPipeableStream:

  • <img> with src, srcSet, sizes, fetchPriority="high", loading="lazy", and inside <picture>
  • 12 images, so that some preloads go into React's bulk queue
  • ReactDOM.preload with as: 'image', with no as, and with an empty as

ReactDOM.preload without as emits nothing, because React requires both as and href. We also ran the same cases through render() from @react-email/render, on the node, edge and browser builds. No image preload was left in the output.

The tag in the issue (<link rel=preload imagesrcset=logo.png-2x />) has no href and no as. I don't think React outputs tags in that form. The only way to get one is to write it by hand in JSX. In that case, render() keeps it on purpose, as it does for any link the user writes that is not an as="image" preload.

I will close this for now. If you have a component and a React version where render() outputs an image preload without as="image", please post them here and we will reopen.

felipefreitag avatar Oct 05 '26 19:10 felipefreitag