Skip to content

fix: render text-only emails in the email preview - #442

Open
ntwcklng wants to merge 1 commit into
usesend:mainfrom
ntwcklng:fix/text-only-email-preview
Open

fix: render text-only emails in the email preview#442
ntwcklng wants to merge 1 commit into
usesend:mainfrom
ntwcklng:fix/text-only-email-preview

Conversation

@ntwcklng

@ntwcklng ntwcklng commented Aug 18, 2026

Copy link
Copy Markdown

Problem

Emails sent with only a text body show an empty preview in the email details view. EmailPreview always feeds email.html ?? "" into the sandboxed iframe, so when html is null the preview box renders blank even though the API already returns the text body.

Easy to reproduce: send an email through the API with text and no html, then open it under Emails in the dashboard.

Fix

  • New helper getEmailPreviewSrcDoc(html, text) in apps/web/src/lib/email-preview.ts: returns the html body unchanged when present, otherwise wraps the escaped text body in a minimal <pre> document for the same sandboxed iframe, or null when the email has neither.
  • email-details.tsx passes both fields and shows a "No content to preview" placeholder for the null case (previously also a silent blank box).

The text body is HTML-escaped before being placed in the srcDoc, so text content can never execute as markup, and the existing iframe sandbox is untouched.

Tests

Unit tests for the helper in apps/web/src/lib/email-preview.unit.test.ts (html passthrough, text fallback, escaping, empty-string handling, no-content case). pnpm test:unit passes. Also verified in the running dashboard against a seeded text-only email: preview was blank before, renders the body with line breaks preserved after.


Summary by cubic

Render text-only emails in the email details preview to fix blank previews. Previously the preview always used email.html ?? ""; now it falls back to text and shows a placeholder when both bodies are absent.

  • Add getEmailPreviewSrcDoc(html, text) to build the iframe srcDoc: returns HTML as-is; otherwise wraps escaped text in a minimal <pre> document; returns null when neither is present.
  • Update EmailPreview to pass both fields, use the computed srcDoc, and render "No content to preview" when null.
  • Treat empty-string HTML as absent; behavior for HTML emails is unchanged.
  • Text is HTML-escaped; the iframe sandbox remains unchanged.
  • Unit tests cover HTML passthrough, text fallback, escaping, empty-string handling, and no-content cases.

Written for commit b355587. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • New Features
    • Email previews now support both HTML and plain-text content.
    • Plain-text emails are converted into safely formatted previews.
    • A clear “No content to preview” state appears when no email content is available.
  • Bug Fixes
    • Special characters in plain-text email previews are safely escaped.
    • Empty HTML content now falls back appropriately.

The email details preview always fed the html body into the iframe, so
emails sent with only a text body showed an empty preview. Fall back to
the text body, escaped and wrapped in a minimal pre document, and show a
placeholder when the email has no content at all.
@vercel

vercel Bot commented Aug 18, 2026

Copy link
Copy Markdown

@ntwcklng is attempting to deploy a commit to the kmkoushik's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2ee58f1f-275f-4b29-80f2-322fc2d141ad

📥 Commits

Reviewing files that changed from the base of the PR and between bd83535 and b355587.

📒 Files selected for processing (3)
  • apps/web/src/app/(dashboard)/emails/email-details.tsx
  • apps/web/src/lib/email-preview.ts
  • apps/web/src/lib/email-preview.unit.test.ts

Included review availability: Your plan includes up to 8 reviews per rolling hour; 7 remain after this review.


Walkthrough

The change adds getEmailPreviewSrcDoc to generate preview documents from HTML or plain-text email content. Plain-text content is HTML-escaped and wrapped in a styled document. The email details view passes both content types to EmailPreview. The component loads generated content in a sandboxed iframe or displays “No content to preview” when no content exists. Unit tests cover the helper behavior.

Merge Risk: ⚪ Minimal · up to b3555

This localized change adds a safe text-only email preview and an explicit no-content state; no actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: rendering text-only emails in the email preview.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

apps/web/src/app/(dashboard)/emails/email-details.tsx

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

apps/web/src/lib/email-preview.ts

ESLint skipped: the matched ESLint configuration already failed (missing-dependency).

apps/web/src/lib/email-preview.unit.test.ts

ESLint skipped: the matched ESLint configuration already failed (missing-dependency).


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant