Skip to content

Strip React 19's image preload links from convertToHTML output - #245

Merged
henryqdineen merged 1 commit into
masterfrom
hqd-react-19-strip-image-preloads
Oct 28, 2026
Merged

henryqdineen merged 1 commit into
masterfrom
hqd-react-19-strip-image-preloads

Conversation

@henryqdineen

Copy link
Copy Markdown
Contributor

React 19's renderToStaticMarkup emits <link rel="preload" as="image" href="…"/> for every <img> (the server half of Suspensey images, react#27191). convertToHTML builds 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.

Other React 19 output changes this does not undo:

  • javascript: hrefs are replaced by React with a blocking throw URL (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, srcSet images, 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

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>
@henryqdineen
henryqdineen marked this pull request as ready for review October 28, 2026 19:46
@henryqdineen
henryqdineen merged commit 3be17ff into master Oct 28, 2026
4 checks passed
@henryqdineen henryqdineen mentioned this pull request Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for React 19 as peer dependency

1 participant