: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
fix(conversations): keep unsaved widget drafts when a sibling field saves (#91257)
posthog[bot]d64df2ff85ab
diff --git a/products/conversations/frontend/scenes/settings/supportSettingsLogic.test.ts b/products/conversations/frontend/scenes/settings/supportSettingsLogic.test.tsindex 34fe4868b897..baf85cbc6db9 100644--- a/products/conversations/frontend/scenes/settings/supportSettingsLogic.test.ts+++ b/products/conversations/frontend/scenes/settings/supportSettingsLogic.test.ts@@ -257,6 +257,59 @@ describe('supportSettingsLogic', () => {})})+ describe('widget draft preservation on save', () => {+ it('clears the saved draft but keeps unsaved sibling drafts', async () => {+ logic = supportSettingsLogic()+ logic.mount()+ await expectLogic(logic).toFinishAllListeners()++ logic.actions.setGreetingInputValue('new greeting')+ logic.actions.setPlaceholderTextValue('unsaved placeholder')++ // A save persists the greeting; the server echoes it back on success.+ logic.actions.updateCurrentTeamSuccess({+ conversations_settings: { widget_greeting_text: 'new greeting' },+ } as unknown as TeamType)++ expect(logic.values.greetingInputValue).toBeNull()+ expect(logic.values.placeholderTextValue).toBe('unsaved placeholder')+ })++ it('clears a bot field draft that was blanked to remove the override', async () => {+ logic = supportSettingsLogic()+ logic.mount()+ await expectLogic(logic).toFinishAllListeners()++ // Clearing the input yields an empty-string draft; the save persists it as null.+ logic.actions.setSlackBotDisplayNameValue('')++ logic.actions.updateCurrentTeamSuccess({+ conversations_settings: { slack_bot_display_name: null },+ } as unknown as TeamType)++ expect(logic.values.slackBotDisplayNameValue).toBeNull()+ })++ it('keeps a whitespace-only emoji edit when an unrelated field saves', async () => {+ initKeaTests(true, {+ conversations_settings: { slack_ticket_emoji: '🎫' },+ } as unknown as TeamType)+ logic = supportSettingsLogic()+ logic.mount()+ await expectLogic(logic).toFinishAllListeners()++ // The emoji saver sends the raw value, so a spaced draft is not yet persisted.+ logic.actions.setSlackTicketEmojiValue(' 🎫 ')++ // An unrelated save echoes the still-stored emoji back.+ logic.actions.updateCurrentTeamSuccess({+ conversations_settings: { slack_ticket_emoji: '🎫' },+ } as unknown as TeamType)++ expect(logic.values.slackTicketEmojiValue).toBe(' 🎫 ')+ })+ })+describe('teamsChannelPairs selector', () => {it('reads the teams_channels list when present', async () => {initKeaTests(true, {diff --git a/products/conversations/frontend/scenes/settings/supportSettingsLogic.ts b/products/conversations/frontend/scenes/settings/supportSettingsLogic.tsindex 9e563c6fc9de..030b18f5ebb4 100644--- a/products/conversations/frontend/scenes/settings/supportSettingsLogic.ts+++ b/products/conversations/frontend/scenes/settings/supportSettingsLogic.ts@@ -1656,13 +1656,52 @@ export const supportSettingsLogic = kea<supportSettingsLogicType>([}},updateCurrentTeamSuccess: ({ payload }) => {- actions.setGreetingInputValue(null)- actions.setIdentificationFormTitleValue(null)- actions.setIdentificationFormDescriptionValue(null)- actions.setPlaceholderTextValue(null)- actions.setSlackTicketEmojiValue(null)- actions.setSlackBotIconUrlValue(null)- actions.setSlackBotDisplayNameValue(null)+ // Clear only the drafts that this save persisted, so unsaved edits to+ // sibling widget fields survive when a neighboring field is saved.+ const saved = values.currentTeam?.conversations_settings+ // A draft is persisted when its save-time representation matches the stored value.+ // Each save listener transforms the draft differently, so normalize per field to+ // match — otherwise a cleared field stays stuck and a whitespace-only edit is lost.+ const isPersisted = (+ draft: string | null,+ storedValue: string | null | undefined,+ normalize: (value: string) => string | null+ ): boolean => draft !== null && storedValue === normalize(draft)++ // Widget text savers send the trimmed value and reject blanks.+ const trimmed = (value: string): string => value.trim()+ // Slack bot savers send the trimmed value, or null when blank.+ const trimmedOrNull = (value: string): string | null => value.trim() || null+ // The emoji saver sends the raw value.+ const raw = (value: string): string => value++ if (isPersisted(values.greetingInputValue, saved?.widget_greeting_text, trimmed)) {+ actions.setGreetingInputValue(null)+ }+ if (isPersisted(values.identificationFormTitleValue, saved?.widget_identification_form_title, trimmed)) {+ actions.setIdentificationFormTitleValue(null)+ }+ if (+ isPersisted(+ values.identificationFormDescriptionValue,+ saved?.widget_identification_form_description,+ trimmed+ )+ ) {+ actions.setIdentificationFormDescriptionValue(null)+ }+ if (isPersisted(values.placeholderTextValue, saved?.widget_placeholder_text, trimmed)) {+ actions.setPlaceholderTextValue(null)+ }+ if (isPersisted(values.slackTicketEmojiValue, saved?.slack_ticket_emoji, raw)) {+ actions.setSlackTicketEmojiValue(null)+ }+ if (isPersisted(values.slackBotIconUrlValue, saved?.slack_bot_icon_url, trimmedOrNull)) {+ actions.setSlackBotIconUrlValue(null)+ }+ if (isPersisted(values.slackBotDisplayNameValue, saved?.slack_bot_display_name, trimmedOrNull)) {+ actions.setSlackBotDisplayNameValue(null)+ }if (payload?.conversations_enabled) {const storedSource = sessionStorage.getItem('support_activation_source')const source = storedSource ? JSON.parse(storedSource) : { source: 'support_settings' }