Skip to content

: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.

fix(surveys): keep the activity history readable with no questions (#119913)

Phill1b02d0466d32
diff --git a/frontend/src/scenes/surveys/surveyActivityDescriber.test.tsx b/frontend/src/scenes/surveys/surveyActivityDescriber.test.tsx
index 5d56642390a8..dfc229cc61d4 100644
--- a/frontend/src/scenes/surveys/surveyActivityDescriber.test.tsx
+++ b/frontend/src/scenes/surveys/surveyActivityDescriber.test.tsx
@@ -1,6 +1,10 @@
import { render } from '@testing-library/react'
+import { ActivityChange, ActivityLogItem } from 'lib/components/ActivityLog/humanizeActivity'
+
import {
+ ActivityScope,
+ BasicSurveyQuestion,
LinkSurveyQuestion,
MultipleSurveyQuestion,
RatingSurveyQuestion,
@@ -17,6 +21,7 @@ import {
describeMultipleChoiceChanges,
describeQuestionChanges,
describeRatingChanges,
+ surveyActivityDescriber,
} from './surveyActivityDescriber'
const getTextContent = (jsxElement: JSX.Element): string => {
@@ -262,3 +267,32 @@ describe('describeQuestionChanges', () => {
expect(getTextContent(changes[5])).toBe('updated branching logic')
})
})
+
+describe('surveyActivityDescriber', () => {
+ const question: BasicSurveyQuestion = {
+ question: 'What do you think?',
+ type: SurveyQuestionType.Open,
+ }
+
+ const questionsChange = (before: ActivityChange['before'], after: ActivityChange['after']): ActivityLogItem => ({
+ activity: 'updated',
+ created_at: '2026-01-01T00:00:00Z',
+ scope: ActivityScope.SURVEY,
+ item_id: '1',
+ user: { first_name: 'Alice', last_name: 'Adams', email: '[email protected]' },
+ detail: {
+ name: 'Example survey',
+ changes: [{ type: ActivityScope.SURVEY, action: 'changed', field: 'questions', before, after }],
+ merge: null,
+ trigger: null,
+ },
+ })
+
+ test.each([
+ ['the questions list was empty before', null, [question], 'from 0 to 1'],
+ ['the questions list is empty after', [question], null, 'from 1 to 0'],
+ ])('describes the question count when %s', (_, before, after, expected) => {
+ const { description } = surveyActivityDescriber(questionsChange(before, after))
+ expect(getTextContent(<>{description}</>)).toContain(expected)
+ })
+})
diff --git a/frontend/src/scenes/surveys/surveyActivityDescriber.tsx b/frontend/src/scenes/surveys/surveyActivityDescriber.tsx
index e8b1fd544598..b0b357f6cd28 100644
--- a/frontend/src/scenes/surveys/surveyActivityDescriber.tsx
+++ b/frontend/src/scenes/surveys/surveyActivityDescriber.tsx
@@ -33,6 +33,10 @@ import { SurveyQuestionLabel } from './constants'
const isEmptyOrUndefined = (value: any): boolean => value === undefined || value === null || value === ''
+// A survey can hold no questions, and the activity log records an empty list as null,
+// so one side of a questions change carries null instead of an array.
+const toQuestionList = (value: unknown): Survey['questions'] => (Array.isArray(value) ? value : [])
+
const nameOrLinkToSurvey = (
id: string | undefined,
name: string | null | undefined,
@@ -86,8 +90,8 @@ const surveyActionsMapping: Record<
return null
}
- const beforeQuestions = change.before as Survey['questions']
- const afterQuestions = change.after as Survey['questions']
+ const beforeQuestions = toQuestionList(change.before)
+ const afterQuestions = toQuestionList(change.after)
if (beforeQuestions.length !== afterQuestions.length) {
return {