Updated welcome email renderer to use custom design settings when enabled#27191
Updated welcome email renderer to use custom design settings when enabled#27191
Conversation
WalkthroughThis pull request implements a feature-flagged design customization system for member welcome emails. It adds support for loading and applying design settings from the database when the 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
|
@CodeRabbit review |
✅ Actions performedReview triggered.
|
ghost/core/core/server/services/member-welcome-emails/member-welcome-email-renderer.js
Outdated
Show resolved
Hide resolved
…hen labs flag is enabled
|
There was a problem hiding this comment.
🧹 Nitpick comments (2)
ghost/core/core/server/services/member-welcome-emails/member-welcome-email-renderer.js (2)
226-235: Consider extractingctaBgColorsto a module-level constant.This static array could be moved alongside
DEFAULT_DESIGN_SETTINGSfor consistency and to make it easier to maintain if the same colors are needed elsewhere.♻️ Optional extraction
+const CTA_BG_COLORS = [ + 'grey', + 'blue', + 'green', + 'yellow', + 'red', + 'pink', + 'purple', + 'white' +]; + class MemberWelcomeEmailRenderer {Then use
ctaBgColors: CTA_BG_COLORSin the template context.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ghost/core/core/server/services/member-welcome-emails/member-welcome-email-renderer.js` around lines 226 - 235, Extract the inline ctaBgColors array into a module-level constant named CTA_BG_COLORS (placed alongside DEFAULT_DESIGN_SETTINGS) and replace the inline property in the template context with ctaBgColors: CTA_BG_COLORS; ensure the new constant is imported or referenced where needed and update any other occurrences of ctaBgColors in member-welcome-email-renderer.js to use the new CTA_BG_COLORS symbol.
151-156: Consider defensive null check fordesignSettings.The default parameter
= {}handlesundefinedbut not explicitnull. If a caller passesnull, accessing properties likedesignSettings.background_colorwould throw a TypeError.Since this is an internal API and the service appears to pass valid objects, this is low risk. However, a defensive check could prevent future bugs:
🛡️ Optional defensive fix
async render({lexical, subject, designSettings = {}, member, siteSettings}) { const useDesignCustomization = labs.isSet('welcomeEmailsDesignCustomization'); if (!useDesignCustomization) { designSettings = DEFAULT_DESIGN_SETTINGS; + } else { + designSettings = designSettings || {}; }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ghost/core/core/server/services/member-welcome-emails/member-welcome-email-renderer.js` around lines 151 - 156, In render({lexical, subject, designSettings = {}, member, siteSettings}) ensure designSettings is treated defensively so an explicit null doesn't cause a TypeError: check if designSettings is falsy or not an object (e.g. null) before using it and, when labs.isSet('welcomeEmailsDesignCustomization') is false or designSettings is null/invalid, assign DEFAULT_DESIGN_SETTINGS to designSettings; update the logic around useDesignCustomization and the designSettings variable in the render function to perform this null/invalid-object check and fallback to DEFAULT_DESIGN_SETTINGS.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In
`@ghost/core/core/server/services/member-welcome-emails/member-welcome-email-renderer.js`:
- Around line 226-235: Extract the inline ctaBgColors array into a module-level
constant named CTA_BG_COLORS (placed alongside DEFAULT_DESIGN_SETTINGS) and
replace the inline property in the template context with ctaBgColors:
CTA_BG_COLORS; ensure the new constant is imported or referenced where needed
and update any other occurrences of ctaBgColors in
member-welcome-email-renderer.js to use the new CTA_BG_COLORS symbol.
- Around line 151-156: In render({lexical, subject, designSettings = {}, member,
siteSettings}) ensure designSettings is treated defensively so an explicit null
doesn't cause a TypeError: check if designSettings is falsy or not an object
(e.g. null) before using it and, when
labs.isSet('welcomeEmailsDesignCustomization') is false or designSettings is
null/invalid, assign DEFAULT_DESIGN_SETTINGS to designSettings; update the logic
around useDesignCustomization and the designSettings variable in the render
function to perform this null/invalid-object check and fallback to
DEFAULT_DESIGN_SETTINGS.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 61120e51-78d3-4ecb-bce5-1148b861d6dc
⛔ Files ignored due to path filters (1)
ghost/core/test/integration/services/__snapshots__/member-welcome-emails-snapshot.test.js.snapis excluded by!**/*.snap
📒 Files selected for processing (1)
ghost/core/core/server/services/member-welcome-emails/member-welcome-email-renderer.js
…bled (#27191) closes https://linear.app/ghost/issue/NY-1197/use-design-settings-from-the-database-when-rendering-welcome-emails ## Summary - Updated the welcome email renderer to use custom design settings (background color, button style, header image, footer content, badge, etc.) from the database instead of hardcoded defaults - All new behavior is gated behind the `welcomeEmailsDesignCustomization` labs flag — existing welcome emails are unchanged when the flag is off - The service wrapper reinitializes when the labs flag changes, so toggling the flag takes effect without a restart ## Changes **Renderer** (`member-welcome-email-renderer.js`): - Reads `designSettings` and passes them through to `getEmailDesign()` (when flag is on) or uses hardcoded defaults (when flag is off) - Reuses `registerHelpers` and the newsletter styles partial for consistent rendering with newsletter emails - Passes header image, footer content, badge, and header title settings to the wrapper template **Service** (`service.js`): - Loads `emailDesignSetting` relation when fetching automated emails (flag-gated) - Caches design settings at load time alongside other email data - Wrapper class tracks labs flag state and reinitializes when it changes **Template** (`wrapper.hbs`): - Added `post-content-row` / `post-content` classes for newsletter-consistent content styling - Added conditional footer content, badge, and powered-by-Ghost sections


closes https://linear.app/ghost/issue/NY-1197/use-design-settings-from-the-database-when-rendering-welcome-emails
Summary
welcomeEmailsDesignCustomizationlabs flag — existing welcome emails are unchanged when the flag is offChanges
Renderer (
member-welcome-email-renderer.js):designSettingsand passes them through togetEmailDesign()(when flag is on) or uses hardcoded defaults (when flag is off)registerHelpersand the newsletter styles partial for consistent rendering with newsletter emailsService (
service.js):emailDesignSettingrelation when fetching automated emails (flag-gated)Template (
wrapper.hbs):post-content-row/post-contentclasses for newsletter-consistent content stylingTest plan