: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): preserve draft state when switching to full editor (#58234)
Lucas Faria665ced9c9c62
diff --git a/frontend/src/scenes/surveys/wizard/surveyWizardLogic.test.ts b/frontend/src/scenes/surveys/wizard/surveyWizardLogic.test.tsindex 5600388a7b45..84eb1aa480b6 100644--- a/frontend/src/scenes/surveys/wizard/surveyWizardLogic.test.ts+++ b/frontend/src/scenes/surveys/wizard/surveyWizardLogic.test.ts@@ -249,6 +249,47 @@ describe('surveyWizardLogic', () => {expect(logic.values.currentStep).toBe('questions')expect(logic.values.survey.description).toBe('Edited in the full editor')})++ it('preserves unsaved guided editor changes when switching to the full editor', async () => {+ // surveyLogic is normally mounted by the destination Survey scene; mount it+ // separately so the wizard logic's connect doesn't tear it down on unmount.+ const surveyFormLogic = surveyLogic({ id: 'new' })+ surveyFormLogic.mount()++ const wizardLogic = surveyWizardLogic({ id: 'new' })+ const unmountWizard = wizardLogic.mount()++ await expectLogic(wizardLogic, () => {+ wizardLogic.actions.setSurveyValue('description', 'Edited in the guided editor')+ }).toMatchValues({+ surveyChanged: true,+ })++ router.actions.push('/surveys/new#preserveLocalChanges=true')+ unmountWizard()++ expect(surveyFormLogic.values.survey.description).toBe('Edited in the guided editor')+ expect(surveyFormLogic.values.surveyChanged).toBe(true)+ })++ it('resets new survey state when leaving the guided editor without preserveLocalChanges', async () => {+ const surveyFormLogic = surveyLogic({ id: 'new' })+ surveyFormLogic.mount()++ const wizardLogic = surveyWizardLogic({ id: 'new' })+ const unmountWizard = wizardLogic.mount()++ await expectLogic(wizardLogic, () => {+ wizardLogic.actions.setSurveyValue('description', 'Discarded edit')+ }).toMatchValues({+ surveyChanged: true,+ })++ router.actions.push('/surveys')+ unmountWizard()++ expect(surveyFormLogic.values.survey.description).toBe('')+ })})describe('template selection', () => {diff --git a/frontend/src/scenes/surveys/wizard/surveyWizardLogic.ts b/frontend/src/scenes/surveys/wizard/surveyWizardLogic.tsindex 75f438a8c8c4..b781bb0efb66 100644--- a/frontend/src/scenes/surveys/wizard/surveyWizardLogic.ts+++ b/frontend/src/scenes/surveys/wizard/surveyWizardLogic.ts@@ -411,7 +411,7 @@ export const surveyWizardLogic = kea<surveyWizardLogicType>([beforeUnmount(({ actions, props }) => {actions.resetWizard()- if (props.id === 'new') {+ if (props.id === 'new' && !router.values.hashParams.preserveLocalChanges) {actions.resetSurvey()}}),