Skip to content

fix(batch): avoid mutating the payload when rendering react emails - #1136

Merged
felipefreitag merged 1 commit into
resend:canaryfrom
jxnnyo:fix/batch-payload-mutation
Oct 15, 2026
Merged

felipefreitag merged 1 commit into
resend:canaryfrom
jxnnyo:fix/batch-payload-mutation

Conversation

@jxnnyo

@jxnnyo jxnnyo commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

#862 stopped emails, broadcasts and templates from mutating the caller's payload, but batch still writes onto each email object when rendering a React component:

email.html = await render(email.react);
email.react = undefined;

So after resend.batch.send(emails), the caller's objects have lost react and gained a rendered html string. If the objects are frozen (e.g. Object.freeze, Immer/Redux state), it throws TypeError: Cannot add property html, object is not extensible instead of returning { data, error }.

This copies each email before rendering, the same way #862 does for the other resources.

How to test it

Added two tests to batch.spec.ts:

  • the payload is unchanged after batch.create() with a React email
  • a frozen payload returns error: null instead of throwing

Both fail on canary and pass with this change. pnpm lint, typecheck and the full test suite pass.


Summary by cubic

Fixes batch mutating the caller's email payloads when React components are used. batch.create and batch.send previously wrote a rendered html string onto each email and removed its react property, which threw a TypeError when the payload was frozen (e.g. with Object.freeze or Immer state). Each email is now copied before rendering, matching the fix already applied to emails, broadcasts, and templates.

Written for commit 24b9484. Summary will update on new commits.

Review in cubic

@jxnnyo
jxnnyo requested a review from a team as a code owner October 6, 2026 08:20
@jxnnyo
jxnnyo requested a review from matt-gilb October 6, 2026 08:20
@github-actions github-actions Bot added the linear-synced PR has been synced to Linear label Oct 6, 2026
@pkg-pr-new

pkg-pr-new Bot commented Oct 15, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/resend@1136

commit: 24b9484

@felipefreitag
felipefreitag merged commit 022286e into resend:canary Oct 15, 2026
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

linear-synced PR has been synced to Linear

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants