: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(settings): avoid no-op redirect when settings link clicked on settings page (#64963)
posthog[bot]f42f11c41d38
diff --git a/frontend/src/scenes/settings/settingsSceneLogic.test.ts b/frontend/src/scenes/settings/settingsSceneLogic.test.tsindex e95e58ff8f2b..cc6f5cd1c417 100644--- a/frontend/src/scenes/settings/settingsSceneLogic.test.ts+++ b/frontend/src/scenes/settings/settingsSceneLogic.test.ts@@ -96,6 +96,8 @@ describe('settingsSceneLogic', () => {})it('redirects level-only URLs to first section', async () => {+ // Each push switches to a different level, so no section at the target level is+ // selected yet and the redirect to the first section runs.router.actions.push('/settings/environment')await expectLogic(logic).toMatchValues({selectedLevel: 'project',@@ -103,12 +105,6 @@ describe('settingsSceneLogic', () => {// Should redirect to first section (project-details)expect(router.values.location.pathname).toContain('/settings/project-details')- router.actions.push('/settings/project')- await expectLogic(logic).toMatchValues({- selectedLevel: 'project',- })- expect(router.values.location.pathname).toContain('/settings/project-details')-router.actions.push('/settings/organization')await expectLogic(logic).toMatchValues({selectedLevel: 'organization',@@ -120,5 +116,28 @@ describe('settingsSceneLogic', () => {selectedLevel: 'user',})expect(router.values.location.pathname).toContain('/settings/user-profile')++ router.actions.push('/settings/project')+ await expectLogic(logic).toMatchValues({+ selectedLevel: 'project',+ })+ expect(router.values.location.pathname).toContain('/settings/project-details')+ })++ it('does not bounce a level-only URL when already on a section at that level', async () => {+ router.actions.push('/settings/project-autocapture')+ await expectLogic(logic).toMatchValues({+ selectedLevel: 'project',+ selectedSectionId: 'project-autocapture',+ })++ // Clicking the "Settings" nav link routes to the bare level URL; while already viewing a+ // project settings page it must be a no-op, not a redirect back to the first section.+ router.actions.push('/settings/project')+ await expectLogic(logic).toMatchValues({+ selectedLevel: 'project',+ selectedSectionId: 'project-autocapture',+ })+ expect(router.values.location.pathname).toMatch(/\/settings\/project$/)})})diff --git a/frontend/src/scenes/settings/settingsSceneLogic.ts b/frontend/src/scenes/settings/settingsSceneLogic.tsindex 7db1f87dd2f5..9a6386713d86 100644--- a/frontend/src/scenes/settings/settingsSceneLogic.ts+++ b/frontend/src/scenes/settings/settingsSceneLogic.ts@@ -141,6 +141,16 @@ export const settingsSceneLogic = kea<settingsSceneLogicType>([// Redirect level-only URLs to the first section at that levelconst level = section as SettingLevelIdconst effectiveLevel = level === 'environment' ? 'project' : level++ // If a section at this level is already selected (e.g. the user clicked the+ // "Settings" nav link while already viewing a settings page here), don't redirect.+ // Otherwise the level-only URL bounces straight back to the section, a no-op URL+ // rewrite that flickers and makes the link feel broken.+ const selectedSectionLevel = values.sections.find((s) => s.id === values.selectedSectionId)?.level+ if (values.selectedSectionId && selectedSectionLevel === effectiveLevel) {+ return+ }+const firstSection = values.sections.find((s) => s.level === effectiveLevel)if (firstSection) {router.actions.replace(urls.settings(firstSection.id))