: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(surveys): guard survey response panel against missing $survey_id (#66017)
Christiaan Hendriksen56c7b2251c7f
diff --git a/frontend/src/lib/components/EventPropertyTabs/EventPropertyTabs.tsx b/frontend/src/lib/components/EventPropertyTabs/EventPropertyTabs.tsxindex 674f8e951a12..4499c1395a28 100644--- a/frontend/src/lib/components/EventPropertyTabs/EventPropertyTabs.tsx+++ b/frontend/src/lib/components/EventPropertyTabs/EventPropertyTabs.tsx@@ -10,7 +10,7 @@ import { LemonTab, LemonTabs, LemonTabsProps } from 'lib/lemon-ui/LemonTabs'import { isKeyOf } from 'lib/utils/guards'import { CORE_FILTER_DEFINITIONS_BY_GROUP, POSTHOG_EVENT_PROMOTED_PROPERTIES } from '~/taxonomy/taxonomy'-import { EventType, RecordingEventType } from '~/types'+import { EventType, RecordingEventType, SurveyEventProperties } from '~/types'import { AutocaptureImageTab, hasAutocaptureImage } from '../AutocapturePreviewImage/AutocapturePreviewImage'import { ErrorEventType } from '../Errors/types'@@ -59,7 +59,7 @@ export const EventPropertyTabs = ({const isAITagEvent = event.event === '$ai_tag'const isErrorEvent = event.event === '$exception'- const isSurveyResponseEvent = event.event === 'survey sent'+ const isSurveyResponseEvent = event.event === 'survey sent' && !!event.properties?.[SurveyEventProperties.SURVEY_ID]const isMcpEvent =typeof event.event === 'string' &&(event.event.startsWith('mcp_') || event.event.startsWith('$mcp_') || event.event.startsWith('mcp '))diff --git a/frontend/src/lib/components/SurveyResponseDisplay/SurveyResponseDisplay.test.tsx b/frontend/src/lib/components/SurveyResponseDisplay/SurveyResponseDisplay.test.tsxnew file mode 100644index 000000000000..e6f8b6dc019c--- /dev/null+++ b/frontend/src/lib/components/SurveyResponseDisplay/SurveyResponseDisplay.test.tsx@@ -0,0 +1,27 @@+import '@testing-library/jest-dom'++import { cleanup, render, screen } from '@testing-library/react'++import { initKeaTests } from '~/test/init'++import { SurveyResponseDisplay } from './SurveyResponseDisplay'++describe('SurveyResponseDisplay', () => {+ beforeEach(() => {+ initKeaTests()+ })++ afterEach(() => {+ cleanup()+ })++ it('renders without mounting surveyLogic when $survey_id is missing', () => {+ render(+ <SurveyResponseDisplay+ eventProperties={{ $survey_name: 'Custom survey sent event', $survey_response: 'hello' }}+ />+ )++ expect(screen.getByText('Custom survey sent event')).toBeInTheDocument()+ })+})diff --git a/frontend/src/lib/components/SurveyResponseDisplay/SurveyResponseDisplay.tsx b/frontend/src/lib/components/SurveyResponseDisplay/SurveyResponseDisplay.tsxindex f047505e5d42..2abb328dff44 100644--- a/frontend/src/lib/components/SurveyResponseDisplay/SurveyResponseDisplay.tsx+++ b/frontend/src/lib/components/SurveyResponseDisplay/SurveyResponseDisplay.tsx@@ -9,12 +9,13 @@ import ViewRecordingButton, { ViewRecordingButtonVariant } from 'lib/components/import { IconLink } from 'lib/lemon-ui/icons'import { countryCodeToFlag } from 'lib/utils/country'import { PersonDisplay } from 'scenes/persons/PersonDisplay'+import { NewSurvey } from 'scenes/surveys/constants'import { getThumbIcon } from 'scenes/surveys/hooks/useSurveyResponseColumns'import { surveyLogic } from 'scenes/surveys/surveyLogic'import { getSurveyResponseValue, isScaleTwoRating } from 'scenes/surveys/utils'import { urls } from 'scenes/urls'-import { SurveyEventProperties as SurveyEventPropertyNames, SurveyQuestion } from '~/types'+import { Survey, SurveyEventProperties as SurveyEventPropertyNames, SurveyQuestion } from '~/types'interface SurveyResponseDisplayProps {eventProperties: Record<string, any>@@ -68,19 +69,39 @@ function MetaItem({ icon, children }: { icon?: JSX.Element; children: React.Reac)}-export function SurveyResponseDisplay({+export function SurveyResponseDisplay(props: SurveyResponseDisplayProps): JSX.Element {+ const surveyId = props.eventProperties[SurveyEventPropertyNames.SURVEY_ID]+ if (!surveyId) {+ return <SurveyResponseContent {...props} />+ }+ return <SurveyResponseDisplayWithLogic {...props} surveyId={surveyId} />+}++function SurveyResponseDisplayWithLogic({+ surveyId,+ ...props+}: SurveyResponseDisplayProps & { surveyId: string }): JSX.Element {+ const { survey, archivedResponseUuids } = useValues(surveyLogic({ id: surveyId }))+ return <SurveyResponseContent {...props} survey={survey} archivedResponseUuids={archivedResponseUuids} />+}++function SurveyResponseContent({eventProperties,eventUuid,distinctId,timestamp,personProperties,-}: SurveyResponseDisplayProps): JSX.Element {+ survey,+ archivedResponseUuids,+}: SurveyResponseDisplayProps & {+ survey?: NewSurvey | Survey+ archivedResponseUuids?: Set<string>+}): JSX.Element {const surveyId = eventProperties[SurveyEventPropertyNames.SURVEY_ID]const { location } = useValues(router)const isOnSurveyPage = surveyId && location.pathname.includes(`/surveys/${surveyId}`)- const { survey, archivedResponseUuids } = useValues(surveyLogic({ id: surveyId }))const isArchived = eventUuid ? (archivedResponseUuids?.has(eventUuid) ?? false) : falseconst surveyName = survey?.name || eventProperties['$survey_name']