SSR: no automatic image preloads for eager <img> elements (React emits <link rel="preload" as="image">)

Aperta
#97 1 commento 1 reazione 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@barrymichaeldoyle ci sta già lavorando.

Dal 28/10/2026.

  • #100 di @barrymichaeldoyle — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
react, typescript
Ambito
backend

Direzione di ricerca

Start by comparing Redact's server renderer with React's pushImg behavior in ReactFizzConfigDOM, then inspect how Redact collects head elements during rendering. Reproduce the issue with the provided renderToString example and check eager images with src, srcSet, loading="lazy", and fetchPriority. Done means matching React's image preload output and ordering; the linked open pull request #100 shows work is already underway.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Version: @tanstack/redact 0.2.1 (same on 0.2.0), TanStack Start 1.168 on Cloudflare Workers, Vite plugin with ssr: { noExternal: true }. Baseline: react-dom 19.3.

React's streaming server renderer emits a <link rel="preload" as="image"> in <head> for images it renders eagerly: every <img> with a src or srcSet that is not loading="lazy", placed before the stylesheet when fetchPriority="high" and after it otherwise (pushImg in ReactFizzConfigDOM). Redact's server renderer emits none, so the browser only discovers the hero image once the parser reaches it in the body.

Same route rendered by both runtimes, head only. React:

<meta charSet="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="preload" as="image" href="/favicon.svg"/>
<link rel="preload" as="image" imageSrcSet="/games/desk-crawler/screen-sample-800.png 800w, /games/desk-crawler/screen-sample.png 1200w" imageSizes="(min-width: 1024px) 560px, 100vw" fetchPriority="high"/>
<link rel="preload" as="image" href="/games/desk-crawler/icon-192.png"/>
<link rel="preload" as="image" href="/games/idle-angler/icon-192.png"/>
<link rel="stylesheet" href="/assets/styles-….css" data-precedence="default"/>
<title>…</title>

Redact:

<link rel="stylesheet" href="/assets/styles-….css" data-precedence="default"/>
<title>…</title>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>

The <img> elements themselves are rendered identically in both (srcset, sizes, fetchpriority="high" all present), and the font <link rel="preload"> elements rendered in the route's head come through fine. It is only the image preloads React synthesises from <img> that are missing.

A smaller related difference, visible above: React hoists <meta charset> and <meta name="viewport"> to the very start of <head>, ahead of stylesheets and the title. Redact keeps them in document order after the stylesheet and title. Here the charset lands at byte 219, inside the 1024-byte window, so it is harmless, but a page with a long stylesheet list or title could push it past the limit.

Reproduction: a renderToString of

<html><head><link rel="stylesheet" href="/a.css" precedence="default" /><title>t</title><meta charSet="utf-8" /></head>
<body><img src="/hero.png" fetchPriority="high" alt="" /></body></html>

gives <meta charSet="utf-8"/><link rel="preload" as="image" href="/hero.png" fetchPriority="high"/><link rel="stylesheet" …/><title>t</title> on react-dom/server, and <link rel="stylesheet" …/><title>t</title><meta charset="utf-8"/> with no preload on @tanstack/redact/server.

Lingua principale
TypeScript
Stelle
581
Fork
28
Merge medio
13h 48m
PR unite (30g)
45

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di TanStack/redact

Tutte le issue di TanStack/redact

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.