Repository navigation
Strip React 19's image preload links from convertToHTML output - #245
Merged
Merged
Conversation
React 19's renderToStaticMarkup emits <link rel="preload" as="image"> for every <img>. convertToHTML joins many small renders, so these links end up in the middle of the output HTML. There is no opt-out in React (react/react#34217). All renderToStaticMarkup calls now go through a wrapper that removes only React's image preload links, and only on React 19+, so output on earlier versions is unchanged. Adds React 19 to the peer range, moves devDependencies to React 19, and runs CI on React 18 as well. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
React 19's
renderToStaticMarkupemits<link rel="preload" as="image" href="…"/>for every<img>(the server half of Suspensey images, react#27191).convertToHTMLbuilds its output from many small renders, so on React 19 these links end up in the middle of the HTML — e.g.<p>x <link rel="preload" as="image" href="a.png"/><img src="a.png"/></p>with 2.1.13. React has no opt-out (react#34217);loading="lazy"/fetchPriority="low"avoid it but change the emitted HTML.renderToStaticMarkupcalls (convertToHTML'sempty,getBlockTags,getElementHTML,splitReactElement×2) now go throughsrc/util/renderToStaticMarkup.js, which removes React's image preloads with a narrow, non-anchored regex covering both attribute orders React emits.@react-email/render(fix(render): strip auto-injected image preload links from rendered HTML resend/react-email#3577). Astro's broader strip of all preload/stylesheet links removed components' own<link>tags and broke hydration (React 19 SSR injects invalid preload into island output withastro/astro#16212).^19.0.0to thereact/react-dompeer ranges. Closes Support for React 19 as peer dependency #224.Other React 19 output changes this does not undo:
javascript:hrefs are replaced by React with a blockingthrowURL (a React security change; pinned in a test).<title>/<meta>/<link>inside block or entity HTML move to just before that element.Tests added for: images in block HTML (
<figure><img/></figure>), several image entities in one block, an image inside an entity element with text,srcSetimages, and non-preload links being kept. All 136 tests pass on React 18.3 and 19.3; with the strip disabled, 8 fail on React 19.🤖 Generated with Claude Code