Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@steven-tey
Copy link
Collaborator

@steven-tey steven-tey commented Nov 28, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Improved email option validation and header handling for more reliable email delivery.
  • Refactor

    • Enhanced internal email implementation for better type safety and consistency.

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel
Copy link
Contributor

vercel bot commented Nov 28, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
dub Ready Ready Preview Nov 28, 2025 3:07am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 28, 2025

Walkthrough

The resendEmailForOptions function in the email service is refactored to explicitly return the CreateEmailOptions type. The function's logic is reorganized to conditionally add rendering fields and headers, with a new type import added for type safety.

Changes

Cohort / File(s) Change Summary
Type safety improvements
packages/email/src/send-via-resend.ts
Added CreateEmailOptions type import from "resend"; updated resendEmailForOptions function signature to explicitly return CreateEmailOptions; refactored base options construction to conditionally add rendering fields (react/text) and headers; added explanatory comments for required content fields and fallback behavior

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Verify the non-null assertion on subject (subject!) is semantically correct and safe
  • Confirm the conditional rendering logic (react β†’ text β†’ empty string fallback) aligns with Resend API requirements
  • Ensure headers conditional merge (headers && { headers }) doesn't inadvertently drop headers when present

Possibly related PRs

  • Bump resend to latestΒ #2930: Both PRs modify the same file and update type imports from "resend" alongside function signatures related to Resend API usage.

Poem

🐰 With types now clear and logic bright,
Our emails dance in Resend's light,
Headers merge with gentle care,
No more any floating there!
Type safety hopsβ€”hooray, hooray! πŸŽ‰

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Upgrade Resend' is vague and generic, using non-specific language that doesn't convey the actual technical changes made to the codebase. Consider a more descriptive title that explains the specific changes, such as 'Type email options in send-via-resend' or 'Improve type safety in Resend email function' to better communicate the primary modification.
βœ… Passed checks (2 passed)
Check name Status Explanation
Description Check βœ… Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage βœ… Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • πŸ“ Generate docstrings
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch upgrade-resend

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 and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/email/src/send-via-resend.ts (1)

53-55: Consider throwing instead of silently sending empty emails.

The fallback to text: "" could mask bugs by sending emails with empty bodies. If this "shouldn't happen in practice," failing early would help catch misuse during development.

-  // If none of react, html, or text is provided, we need to ensure at least one is present
-  // This shouldn't happen in practice, but we'll default to an empty text
-  return { ...baseOptions, text: "" };
+  // This shouldn't happen - fail early to catch misuse
+  throw new Error("Email must have at least one of: react, html, or text");
πŸ“œ Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between ed3c9cc and 98a70aa.

πŸ“’ Files selected for processing (1)
  • packages/email/src/send-via-resend.ts (3 hunks)
🧰 Additional context used
🧠 Learnings (1)
πŸ“š Learning: 2025-09-12T21:08:43.990Z
Learnt from: TWilson023
Repo: dubinc/dub PR: 2835
File: apps/web/ui/analytics/feedback/action.ts:10-13
Timestamp: 2025-09-12T21:08:43.990Z
Learning: In the Dub email system, sendViaNodeMailer is intentionally designed as a simple backup mechanism with hard-coded sender fields, not as a full-featured email sender that preserves all metadata like from/replyTo fields. The primary email path uses Resend for full functionality.

Applied to files:

  • packages/email/src/send-via-resend.ts
🧬 Code graph analysis (1)
packages/email/src/send-via-resend.ts (2)
packages/email/src/resend/types.ts (1)
  • ResendEmailOptions (3-8)
packages/email/src/resend/constants.ts (1)
  • VARIANT_TO_FROM_MAP (3-7)
πŸ”‡ Additional comments (4)
packages/email/src/send-via-resend.ts (4)

1-1: LGTM!

Good use of import type for type-only imports, which improves tree-shaking and makes the intent clear.


6-8: LGTM!

Explicit return type annotation improves type safety and serves as documentation for consumers of this function.


42-42: LGTM!

Clean conditional spreading pattern that avoids including empty or undefined headers.


28-28: Non-null assertion on subject may mask missing subjects.

The subject! assertion bypasses TypeScript's null checks. If a caller accidentally omits subject, this will silently pass the undefined value to Resend, potentially causing API errors or sending emails without subjects.

Consider either:

  1. Validating subject at runtime with a guard
  2. Making subject required in ResendEmailOptions if it should always be present
-    subject: subject!,
+    subject: subject ?? "",

Or add validation:

if (!subject) {
  throw new Error("Email subject is required");
}
β›” Skipped due to learnings
Learnt from: devkiran
Repo: dubinc/dub PR: 3113
File: apps/web/app/(ee)/api/cron/payouts/charge-succeeded/send-paypal-payouts.ts:65-75
Timestamp: 2025-11-17T05:19:11.972Z
Learning: In the Dub codebase, `sendBatchEmail` (implemented in packages/email/src/send-via-resend.ts) handles filtering of emails with invalid `to` addresses internally. Call sites can safely use non-null assertions on email addresses because the email sending layer will filter out any entries with null/undefined `to` values before sending. This centralized validation pattern is intentional and removes the need for filtering at individual call sites.

@steven-tey steven-tey merged commit 6b903ee into main Nov 28, 2025
7 of 8 checks passed
@steven-tey steven-tey deleted the upgrade-resend branch November 28, 2025 03:11
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.

2 participants