:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(workflows): edit the subject in place and put the test email first on broadcast review (#120594)
Daniel Marchuk9c9b0c6cd292
diff --git a/products/workflows/frontend/Broadcasts/BroadcastEmailPreview.tsx b/products/workflows/frontend/Broadcasts/BroadcastEmailPreview.tsxindex 05d56f597137..8ac305081467 100644--- a/products/workflows/frontend/Broadcasts/BroadcastEmailPreview.tsx+++ b/products/workflows/frontend/Broadcasts/BroadcastEmailPreview.tsx@@ -24,8 +24,10 @@ function PreviewRow({ label, children }: { label: string; children: React.ReactN*/export function BroadcastEmailPreview({intro = 'Preview and test before this reaches the audience.',+ showTestButton = true,}: {intro?: string+ showTestButton?: boolean}): JSX.Element {const { email } = useValues(broadcastWizardLogic)const {@@ -47,15 +49,17 @@ export function BroadcastEmailPreview({<div className="flex flex-col gap-3"><div className="flex flex-wrap items-center justify-between gap-2"><span className="text-muted text-xs">{intro}</span>- <LemonButton- type="secondary"- size="small"- icon={<IconSend />}- onClick={() => setModalOpen(true)}- data-attr="broadcast-open-test-email"- >- Send test email- </LemonButton>+ {showTestButton ? (+ <LemonButton+ type="secondary"+ size="small"+ icon={<IconSend />}+ onClick={() => setModalOpen(true)}+ data-attr="broadcast-open-test-email"+ >+ Send test email+ </LemonButton>+ ) : null}</div><SendTestBroadcastModal />diff --git a/products/workflows/frontend/Broadcasts/broadcastTestSendLogic.ts b/products/workflows/frontend/Broadcasts/broadcastTestSendLogic.tsindex 154ec7237f22..d16e80655dbc 100644--- a/products/workflows/frontend/Broadcasts/broadcastTestSendLogic.ts+++ b/products/workflows/frontend/Broadcasts/broadcastTestSendLogic.ts@@ -3,6 +3,7 @@ import { loaders } from 'kea-loaders'import api from 'lib/api'import { lemonToast } from 'lib/lemon-ui/LemonToast'+import { objectsEqual } from 'lib/utils/objects'import { isEmail } from 'lib/utils/url'import { teamLogic } from 'scenes/teamLogic'import { userLogic } from 'scenes/userLogic'@@ -51,6 +52,11 @@ export interface broadcastTestSendLogicValues {currentTeamId: number | null // teamLogicuser: UserType | null // userLogicisModalOpen: boolean+ lastTestSent: {+ email: BroadcastEmailValue+ to: string+ } | null+ lastTestSentTo: string | nullrecipientEmail: stringsendDisabledReason: string | undefinedtestSendResult: HogflowTestResult | null@@ -81,6 +87,13 @@ export interface broadcastTestSendLogicActions {value: true}}+ markTestSent: (+ to: string,+ email: BroadcastEmailValue+ ) => {+ email: BroadcastEmailValue+ to: string+ }sendTestEmail: () => anysendTestEmailFailure: (error: string,@@ -108,6 +121,13 @@ export interface broadcastTestSendLogicActions {export interface broadcastTestSendLogicMeta {key: string__keaTypeGenInternalSelectorTypes: {+ lastTestSentTo: (+ lastTestSent: {+ email: BroadcastEmailValue+ to: string+ } | null,+ email: BroadcastEmailValue+ ) => string | nulltestSendSkipReason: (testSendResult: HogflowTestResult | null) => string | undefinedsendDisabledReason: (email: BroadcastEmailValue, recipientEmail: string) => string | undefined}@@ -147,14 +167,19 @@ export const broadcastTestSendLogic = kea<broadcastTestSendLogicType>([setModalOpen: (open: boolean) => ({ open }),setRecipientEmail: (email: string) => ({ email }),clearTestSendResult: true,+ markTestSent: (to: string, email: BroadcastEmailValue) => ({ to, email }),}),reducers({isModalOpen: [false, { setModalOpen: (_, { open }) => open }],recipientEmail: ['', { setRecipientEmail: (_, { email }) => email }],+ lastTestSent: [+ null as { to: string; email: BroadcastEmailValue } | null,+ { markTestSent: (_, { to, email }) => ({ to, email }) },+ ],}),- loaders(({ values }) => ({+ loaders(({ values, cache }) => ({testSendResult: [null as HogflowTestResult | null,{@@ -162,6 +187,8 @@ export const broadcastTestSendLogic = kea<broadcastTestSendLogicType>([sendTestEmail: async (): Promise<HogflowTestResult> => {const { broadcast, email, emailSettings, name, previewPerson, recipientEmail, currentTeamId } =values+ // The recipient field stays editable while the send runs, so remember what this send used.+ cache.pendingTest = { to: recipientEmail, email }const emailAction: HogFlowAction = {id: TEST_EMAIL_ACTION_ID,@@ -239,6 +266,14 @@ export const broadcastTestSendLogic = kea<broadcastTestSendLogicType>([})),selectors({+ // Only vouches for the email as it was tested. Any later change, typed or from another editor, clears it.+ lastTestSentTo: [+ (s) => [s.lastTestSent, s.email],+ (+ lastTestSent: { to: string; email: BroadcastEmailValue } | null,+ email: BroadcastEmailValue+ ): string | null => (lastTestSent && objectsEqual(lastTestSent.email, email) ? lastTestSent.to : null),+ ],testSendSkipReason: [(s) => [s.testSendResult],(testSendResult: HogflowTestResult | null): string | undefined => findTestSendSkipReason(testSendResult),@@ -263,7 +298,7 @@ export const broadcastTestSendLogic = kea<broadcastTestSendLogicType>([],}),- listeners(({ actions, values }) => ({+ listeners(({ actions, values, cache }) => ({setModalOpen: ({ open }) => {// A stale result from a previous attempt must not greet the next one.actions.clearTestSendResult()@@ -276,7 +311,10 @@ export const broadcastTestSendLogic = kea<broadcastTestSendLogicType>([if (values.testSendSkipReason) {lemonToast.warning('Nothing was sent, see why below')} else if (testSendResult?.status === 'success') {- lemonToast.success(`Test email sent to ${values.recipientEmail}`)+ lemonToast.success(`Test email sent to ${cache.pendingTest?.to ?? values.recipientEmail}`)+ if (cache.pendingTest) {+ actions.markTestSent(cache.pendingTest.to, cache.pendingTest.email)+ }actions.setModalOpen(false)} else if (testSendResult?.status === 'skipped') {lemonToast.warning('The email step was skipped, so nothing was sent')diff --git a/products/workflows/frontend/Broadcasts/broadcastWizardLogic.test.ts b/products/workflows/frontend/Broadcasts/broadcastWizardLogic.test.tsindex 66b51f9edf84..6f8ec588b292 100644--- a/products/workflows/frontend/Broadcasts/broadcastWizardLogic.test.ts+++ b/products/workflows/frontend/Broadcasts/broadcastWizardLogic.test.ts@@ -15,6 +15,7 @@ import type { BlastRadiusApi, HogFlowApi } from 'products/workflows/frontend/genimport { draftMessage } from '../MessageAudience/messageDrafts'import { urlForNewBroadcastWithAudience } from './broadcastAudiencePrefill'+import { broadcastTestSendLogic } from './broadcastTestSendLogic'import { DEFAULT_BROADCAST_EMAIL, DELETED_SENDER_ERROR, broadcastWizardLogic } from './broadcastWizardLogic'const LOCAL_AUDIENCE: AnyPropertyFilter[] = [@@ -94,6 +95,10 @@ describe('broadcastWizardLogic', () => {},post: {'/api/projects/:team_id/hog_flows/user_blast_radius/': () => [200, { affected: 0, total: 0 }],+ '/api/projects/:team_id/hog_flows/new/invocations/': () => [+ 200,+ { status: 'success', nextActionId: null, logs: [] },+ ],'/api/projects/:team_id/hog_flows/': async () => {await createdreturn [201, savedBroadcast({ name: '', subject: '', updatedAt: '2026-09-24T10:00:00Z' })]@@ -134,6 +139,33 @@ describe('broadcastWizardLogic', () => {logic.unmount()})+ it('remembers a delivered test, for the address it went to, until the email changes', async () => {+ const testSend = broadcastTestSendLogic({ id: 'new' })+ testSend.mount()+ // Let the wizard fill its default sender first, which is an email change of its own.+ await expectLogic(logic).toFinishAllListeners()+ const sendTest = async (): Promise<void> => {+ testSend.actions.setRecipientEmail('[email protected]')+ testSend.actions.sendTestEmail()+ // Edited while the send runs, which must not change who the card says got it.+ testSend.actions.setRecipientEmail('[email protected]')+ await expectLogic(testSend).toDispatchActions(['sendTestEmailSuccess']).toFinishAllListeners()+ }++ await sendTest()+ expect(testSend.values.lastTestSentTo).toBe('[email protected]')+ logic.actions.setEmail({ ...logic.values.email, subject: 'Changed after the test' })+ expect(testSend.values.lastTestSentTo).toBeNull()++ await sendTest()+ logic.actions.applyExternalEdit(+ savedBroadcast({ name: '', subject: 'Rewritten by the assistant', updatedAt: '2026-09-24T10:00:09Z' }),+ null+ )+ expect(testSend.values.lastTestSentTo).toBeNull()+ testSend.unmount()+ })+it('prefills the audience, name and source from a link without creating a draft', async () => {const properties: AnyPropertyFilter[] = [{ key: 'id', type: PropertyFilterType.Cohort, value: 7, operator: PropertyOperator.In },@@ -385,6 +417,19 @@ describe('broadcastWizardLogic', () => {expect(router.values.location.pathname).toContain('/broadcasts/broadcast-1')})+ it('autosaves a subject edited in place on the review step', async () => {+ router.actions.push('/broadcasts/new')+ logic.actions.setStep('content')+ releaseCreate()+ await expectLogic(logic).toDispatchActions(['draftAutosaved']).toFinishAllListeners()++ logic.actions.setStep('review')+ logic.actions.setEmail({ ...logic.values.email, subject: 'Edited on the review step' })+ await expectLogic(logic).toDispatchActions(['draftAutosaved']).toFinishAllListeners()++ expect(patchedSubjects.at(-1)).toBe('Edited on the review step')+ })+it('retries a failed email autosave and moves to the draft URL once it saves', async () => {router.actions.push('/broadcasts/new')logic.actions.setStep('content')diff --git a/products/workflows/frontend/Broadcasts/broadcastWizardLogic.ts b/products/workflows/frontend/Broadcasts/broadcastWizardLogic.tsindex e49ac15888b1..c557f473f6c0 100644--- a/products/workflows/frontend/Broadcasts/broadcastWizardLogic.ts+++ b/products/workflows/frontend/Broadcasts/broadcastWizardLogic.ts@@ -1584,10 +1584,11 @@ export const broadcastWizardLogic = kea<broadcastWizardLogicType>([}cache.emailEditPending = true// Read before the wait: a Continue in flight moves the step on, but its save may not carry this edit.- const editedOnContent = values.currentStep === 'content'+ // The review step edits the subject and preheader in place, so its edits save the same way.+ const editedInPlace = values.currentStep === 'content' || values.currentStep === 'review'const saves = getSaveQueue(cache, values)await saves.whenIdle()- if (!editedOnContent || values.broadcast?.status !== 'draft') {+ if (!editedInPlace || values.broadcast?.status !== 'draft') {clearPending()return}diff --git a/products/workflows/frontend/Broadcasts/steps/BroadcastReviewStep.tsx b/products/workflows/frontend/Broadcasts/steps/BroadcastReviewStep.tsxindex c486b4d60c57..8d3577530cda 100644--- a/products/workflows/frontend/Broadcasts/steps/BroadcastReviewStep.tsx+++ b/products/workflows/frontend/Broadcasts/steps/BroadcastReviewStep.tsx@@ -1,7 +1,7 @@import { useActions, useMountedLogic, useValues } from 'kea'import { IconWarning } from '@posthog/icons'-import { LemonButton, Spinner } from '@posthog/lemon-ui'+import { LemonButton, LemonInput, LemonLabel, Spinner } from '@posthog/lemon-ui'import PropertyFiltersDisplay from 'lib/components/PropertyFilters/components/PropertyFiltersDisplay'import { integrationsLogic } from 'lib/integrations/integrationsLogic'@@ -17,6 +17,7 @@ import { BroadcastAudienceCohorts } from '../audience/BroadcastAudienceCohorts'import { broadcastAudienceCohortsLogic } from '../audience/broadcastAudienceCohortsLogic'import { BroadcastEmailPreview } from '../BroadcastEmailPreview'import { BroadcastWizardStep, SENDERS_LOAD_FAILED_ERROR, broadcastWizardLogic } from '../broadcastWizardLogic'+import { BroadcastReviewTestEmail } from './BroadcastReviewTestEmail'function ReviewRow({label,@@ -77,11 +78,13 @@ export function BroadcastReviewStep(): JSX.Element {emailSettings,missingRecipientEmail,aiEmailDraftStatus,+ email,+ launching,} = useValues(broadcastWizardLogic)const { categories } = useValues(optOutCategoriesLogic())const category = categories.find((item) => item.id === emailSettings.messageCategoryId)const { props } = useMountedLogic(broadcastWizardLogic)- const { openInWorkflowEditor } = useActions(broadcastWizardLogic)+ const { openInWorkflowEditor, setEmail } = useActions(broadcastWizardLogic)const { nonCohortAudience } = useValues(broadcastAudienceCohortsLogic(props))const { integrationsLoading } = useValues(integrationsLogic)const { loadIntegrations } = useActions(integrationsLogic)@@ -108,6 +111,8 @@ export function BroadcastReviewStep(): JSX.Element {<p className="m-0 text-secondary">Check everything before sending. Emails can't be unsent.</p></div>+ <BroadcastReviewTestEmail />+<div className="flex flex-col gap-3 rounded-lg border border-border bg-surface-primary p-4"><ReviewRow label="Recipients" step="recipients">{blastRadiusLoading ? (@@ -160,7 +165,38 @@ export function BroadcastReviewStep(): JSX.Element {)}{emailSettings.utmTagsEnabled && <div className="text-xs text-secondary">Links get UTM tags.</div>}{aiEmailDraftStatus ? <AiEmailDraftStatus {...aiEmailDraftStatus} /> : null}- <BroadcastEmailPreview />+ <div className="@container">+ <div className="grid grid-cols-1 gap-2 @lg:grid-cols-2">+ <div className="flex flex-col gap-1">+ <LemonLabel htmlFor="broadcast-review-subject">Subject</LemonLabel>+ <LemonInput+ id="broadcast-review-subject"+ value={email.subject ?? ''}+ onChange={(subject) => setEmail({ ...email, subject })}+ placeholder="Add a subject"+ disabledReason={launching ? 'Sending the broadcast' : undefined}+ data-attr="broadcast-review-subject"+ />+ </div>+ <div className="flex flex-col gap-1">+ <LemonLabel+ htmlFor="broadcast-review-preheader"+ info="The preview text inboxes show next to the subject."+ >+ Preheader+ </LemonLabel>+ <LemonInput+ id="broadcast-review-preheader"+ value={email.preheader ?? ''}+ onChange={(preheader) => setEmail({ ...email, preheader })}+ placeholder="Optional"+ disabledReason={launching ? 'Sending the broadcast' : undefined}+ data-attr="broadcast-review-preheader"+ />+ </div>+ </div>+ </div>+ <BroadcastEmailPreview showTestButton={false} /></ReviewRow><ReviewRow label="Schedule" step="schedule">diff --git a/products/workflows/frontend/Broadcasts/steps/BroadcastReviewTestEmail.tsx b/products/workflows/frontend/Broadcasts/steps/BroadcastReviewTestEmail.tsxnew file mode 100644index 000000000000..e132fa35c0f4--- /dev/null+++ b/products/workflows/frontend/Broadcasts/steps/BroadcastReviewTestEmail.tsx@@ -0,0 +1,42 @@+import { useActions, useMountedLogic, useValues } from 'kea'++import { IconCheckCircle, IconSend } from '@posthog/icons'+import { LemonButton } from '@posthog/lemon-ui'++import { broadcastTestSendLogic } from '../broadcastTestSendLogic'+import { broadcastWizardLogic } from '../broadcastWizardLogic'++export function BroadcastReviewTestEmail(): JSX.Element {+ const { props } = useMountedLogic(broadcastWizardLogic)+ const { lastTestSentTo } = useValues(broadcastTestSendLogic(props))+ const { setModalOpen } = useActions(broadcastTestSendLogic(props))++ return (+ <div+ className="flex flex-wrap items-center justify-between gap-3 rounded-lg border border-border bg-surface-primary p-4"+ data-attr="broadcast-review-test-email"+ >+ <div className="flex min-w-0 flex-1 items-start gap-2">+ {lastTestSentTo ? <IconCheckCircle className="mt-0.5 shrink-0 text-success text-lg" /> : null}+ <div className="flex min-w-0 flex-col">+ <span className="font-semibold">+ {lastTestSentTo ? `Test sent to ${lastTestSentTo}` : 'Send yourself a test first'}+ </span>+ <span className="text-secondary text-xs">+ {lastTestSentTo+ ? 'Check it in your inbox, on desktop and mobile, before you send.'+ : 'Read the email in a real inbox and click its links before it reaches your audience.'}+ </span>+ </div>+ </div>+ <LemonButton+ type={lastTestSentTo ? 'secondary' : 'primary'}+ icon={<IconSend />}+ onClick={() => setModalOpen(true)}+ data-attr="broadcast-review-send-test"+ >+ {lastTestSentTo ? 'Send another test' : 'Send test email'}+ </LemonButton>+ </div>+ )+}