fix: render text-only emails in the email preview - #442
Conversation
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.
|
@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. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan includes up to 8 reviews per rolling hour; 7 remain after this review. WalkthroughThe change adds Merge Risk: ⚪ Minimal · up to 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)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
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
apps/web/src/app/(dashboard)/emails/email-details.tsxESLint 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.tsESLint skipped: the matched ESLint configuration already failed (missing-dependency). apps/web/src/lib/email-preview.unit.test.tsESLint 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. Comment |
Problem
Emails sent with only a
textbody show an empty preview in the email details view.EmailPreviewalways feedsemail.html ?? ""into the sandboxed iframe, so whenhtmlis 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
textand nohtml, then open it under Emails in the dashboard.Fix
getEmailPreviewSrcDoc(html, text)inapps/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, ornullwhen the email has neither.email-details.tsxpasses both fields and shows a "No content to preview" placeholder for thenullcase (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:unitpasses. 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 totextand shows a placeholder when both bodies are absent.getEmailPreviewSrcDoc(html, text)to build the iframesrcDoc: returns HTML as-is; otherwise wraps escaped text in a minimal<pre>document; returns null when neither is present.EmailPreviewto pass both fields, use the computedsrcDoc, and render "No content to preview" when null.Written for commit b355587. Summary will update on new commits.
Summary by CodeRabbit