render: Prettier is bundled even when `pretty` is never used

Aperta
#3,878 1 commento 1 reazione 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
react, typescript, vite

Direzione di ricerca

Start by tracing how render() handles the pretty option and how the package exports render and pretty; the issue names no source files or tests. Compare the proposed core entry point with removing the option in a major release, then check how each affects bundler output for the Vite SSR reproduction. Done means callers that never use pretty can avoid Prettier in their bundle while pretty formatting remains available.

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

Descrizione

Versions

react-email 6.11.8, @react-email/render 2.2.0, prettier 3.9.10

Problem

render() only uses Prettier when options.pretty is set, but because that branch reaches import("prettier/standalone"), bundlers have to include Prettier for every caller of render. The option is only known at runtime, so the import can't be tree-shaken.

In a Vite SSR build for Cloudflare Workers that never sets pretty, the Worker bundle gets two extra chunks:

Chunk Raw Gzip
prettier/standalone 103 KB 30 KB
prettier/plugins/html 197 KB 55 KB
Total 299 KB 85 KB

The code never runs, but it still counts toward the Worker's upload size.

Relation to #3608

#3608 asked to drop Prettier as a dependency, and I'm not asking for that. It's fine as a dependency, and these numbers match the 83 KB gzipped mentioned there. Using a bundler was the suggested fix, but the bundler is what can't remove it here.

To reproduce
import { render } from 'react-email';

export const getHtml = (body: React.ReactElement) => render(body);

Build this for SSR with Vite and look for standalone-*.js and html-*.js in the output.

Suggested fix

pretty is already a separate export and the package has "sideEffects": false, so the if (options?.pretty) branch in render is the only thing keeping Prettier in the graph. Either of these would let bundlers drop it:

  1. Add an entry point whose render has no pretty option, such as @react-email/render/core. This is non-breaking.
  2. Deprecate the option in favour of pretty(await render(element)), and remove it in the next major version.
Lingua principale
TypeScript
Stelle
19.9k
Fork
1.1k
Merge medio
2g 15h
PR unite (30g)
61

Preparare l'ambiente

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 resend/react-email

Tutte le issue di resend/react-email

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.