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

Open
#3,878 2 comments 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
react, typescript, vite

Research direction

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.

Written by the indexing model from the issue text.

Description

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.
Dominant language
TypeScript
Stars
20k
Forks
1.1k
Avg merge
2d 4h
Merged PRs (30d)
80

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from resend/react-email

All issues in resend/react-email

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.