: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(navigation): stop telling people a page does not exist when it does (#102902)
posthog[bot]513c16430209
diff --git a/frontend/src/scenes/dashboard/dashboardLogic.test.ts b/frontend/src/scenes/dashboard/dashboardLogic.test.tsindex e58901b599a5..c2d3d513df09 100644--- a/frontend/src/scenes/dashboard/dashboardLogic.test.ts+++ b/frontend/src/scenes/dashboard/dashboardLogic.test.ts@@ -21,7 +21,10 @@ import { dashboardInsightColorsModalLogic } from 'scenes/dashboard/dashboardInsiimport { DashboardLoadAction, dashboardLogic } from 'scenes/dashboard/dashboardLogic'import * as dashboardUtils from 'scenes/dashboard/dashboardUtils'import * as widgetFetchUtils from 'scenes/dashboard/widgetFetchUtils'+import { sceneLogic } from 'scenes/sceneLogic'+import { Scene } from 'scenes/sceneTypes'import { teamLogic } from 'scenes/teamLogic'+import { urls } from 'scenes/urls'import { resumeKeaLoadersErrors, silenceKeaLoadersErrors } from '~/initKea'import { useMocks } from '~/mocks/jest'@@ -2292,6 +2295,30 @@ describe('dashboardLogic', () => {expect(logic.values.dashboardFailedToLoad).toBe(false)expect(logic.values.error404).toBe(true)})++ // Logging in lands a person on their configured home. When that home is this dashboard and+ // it was deleted, this screen is all they ever see, so the stale setting must go.+ it('clears a configured homepage that points at this dashboard', async () => {+ const scene = sceneLogic({ scenes: {} })+ scene.mount()+ scene.actions.setHomepage({+ id: 'homepage-dashboard',+ pathname: urls.dashboard(13),+ search: '',+ hash: '',+ title: 'Home dashboard',+ iconType: 'dashboard',+ sceneId: Scene.Dashboard,+ sceneParams: { params: {}, searchParams: {}, hashParams: {} },+ })+ router.actions.push(urls.dashboard(13))++ await expectLogic(logic).toFinishAllListeners()+ await expectLogic(scene).toFinishAllListeners()++ expect(scene.values.homepage).toBeNull()+ scene.unmount()+ })})})diff --git a/frontend/src/scenes/dashboard/dashboardLogic.tsx b/frontend/src/scenes/dashboard/dashboardLogic.tsxindex baa7ee046908..98ee44eb98ae 100644--- a/frontend/src/scenes/dashboard/dashboardLogic.tsx+++ b/frontend/src/scenes/dashboard/dashboardLogic.tsx@@ -62,6 +62,7 @@ import { dataThemeLogic } from 'scenes/dataThemeLogic'import { dataRetentionBannerLogic } from 'scenes/insights/dataRetention/dataRetentionBannerLogic'import { exceedsRetention } from 'scenes/insights/dataRetention/exceedsRetention'import { MaxContextInput, createMaxContextHelpers } from 'scenes/max/maxTypes'+import { sceneLogic } from 'scenes/sceneLogic'import { Scene } from 'scenes/sceneTypes'import { urls } from 'scenes/urls'import { userLogic } from 'scenes/userLogic'@@ -4638,6 +4639,9 @@ export const dashboardLogic = kea<dashboardLogicType>([}},tileStreamingComplete: sharedListeners.handleDashboardLoadComplete,+ dashboardNotFound: () => {+ sceneLogic.findMounted()?.actions.resetUnavailableHomepage(urls.dashboard(props.id))+ },reportInsightsViewed: ({ insights }: { insights: QueryBasedInsightModel[] }) => {const insightIds = insights.map((insight: QueryBasedInsightModel) => insight?.id)diff --git a/frontend/src/scenes/sceneLogic.test.tsx b/frontend/src/scenes/sceneLogic.test.tsxindex 5a0ec60c86fe..be0a302a3975 100644--- a/frontend/src/scenes/sceneLogic.test.tsx+++ b/frontend/src/scenes/sceneLogic.test.tsx@@ -31,8 +31,11 @@ const sceneImport = (): any => ({ scene: { component: Component, logic: testLogiconst testScenes: Record<string, () => any> = {[Scene.Alerts]: sceneImport,+ [Scene.Billing]: sceneImport,[Scene.DataManagement]: sceneImport,+ [Scene.OrganizationCreateFirst]: sceneImport,[Scene.PasswordResetComplete]: sceneImport,+ [Scene.ProjectCreateFirst]: sceneImport,[Scene.Settings]: sceneImport,}@@ -103,6 +106,31 @@ describe('sceneLogic', () => {expect(removeProjectIdIfPresent(router.values.location.pathname)).toEqual(urls.billingAuthorizationStatus())})+ it.each([+ ['/organization', urls.settings('organization'), Scene.Settings],+ ['/organization/projects', urls.settings('organization'), Scene.Settings],+ ['/organization/settings/projects', urls.settings('organization'), Scene.Settings],+ ['/organization/projects/new', urls.projectCreateFirst(), Scene.ProjectCreateFirst],+ ['/organization/create', urls.organizationCreateFirst(), Scene.OrganizationCreateFirst],+ ['/organization/new', urls.organizationCreateFirst(), Scene.OrganizationCreateFirst],+ ])('sends the unrouted %s to %s instead of the 404 scene', async (path, expected, expectedScene) => {+ router.actions.push(path)+ await expectLogic(logic).delay(1)+ expect(logic.values.activeSceneId).toEqual(expectedScene)+ expect(removeProjectIdIfPresent(router.values.location.pathname)).toEqual(expected)+ })++ // The redirect table is keyed on exact paths, so a later `/organization/*` prefix entry would+ // shadow the real scenes under it.+ it('keeps /organization/billing on its own scene route, not the organization redirect', async () => {+ router.actions.push(urls.organizationBilling())+ await expectLogic(logic).delay(1)+ // The `/*` fallback leaves the pathname alone, so only the scene tells a shadowed route apart+ // from a served one.+ expect(logic.values.activeSceneId).toEqual(Scene.Billing)+ expect(removeProjectIdIfPresent(router.values.location.pathname)).toEqual(urls.organizationBilling())+ })+it('redirects /project/new to the create-project flow instead of a 404', async () => {router.actions.push('/project/new')await expectLogic(logic).delay(1)@@ -316,6 +344,64 @@ describe('sceneLogic', () => {expect(redirectedPathname).toEqual(urls.projectHomepage())})+ it('drops a homepage whose object turned out not to exist, and lands on the launchpad', async () => {+ logic.actions.setHomepage(dashboardHomepage)+ router.actions.push(urls.projectHomepage())+ await expectLogic(logic).delay(1)+ expect(removeProjectIdIfPresent(router.values.location.pathname)).toEqual(urls.dashboard(42))++ logic.actions.resetUnavailableHomepage(urls.dashboard(42))+ await expectLogic(logic).delay(1)++ expect(logic.values.homepage).toBeNull()+ expect(removeProjectIdIfPresent(router.values.location.pathname)).toEqual(urls.projectHomepage())+ })++ // The way out of the dead end must keep the URL state the `/` → homepage redirect already+ // forwards, or a modal bound to `?modal=` closes itself as the person lands on the launchpad.+ it('carries the hash and allow-listed params onto the launchpad when it drops the homepage', async () => {+ logic.actions.setHomepage(dashboardHomepage)+ router.actions.push(urls.projectHomepage(), { modal: 'invite-members' }, { panel: 'max:hi' })+ await expectLogic(logic).delay(1)+ expect(removeProjectIdIfPresent(router.values.location.pathname)).toEqual(urls.dashboard(42))++ logic.actions.resetUnavailableHomepage(urls.dashboard(42))+ await expectLogic(logic).delay(1)++ expect(removeProjectIdIfPresent(router.values.location.pathname)).toEqual(urls.projectHomepage())+ expect(router.values.searchParams).toEqual({ modal: 'invite-members' })+ expect(router.values.hashParams).toEqual({ panel: 'max:hi' })+ })++ // The reset fires from whichever logic found its object missing, and dashboard logics are+ // also mounted embedded — in notebooks, on the feature flag page — so a missing object that+ // is not the homepage must leave both the setting and the address bar alone.+ it('keeps the homepage when some other object is the missing one', async () => {+ logic.actions.setHomepage(dashboardHomepage)+ router.actions.push(urls.dashboard(99))+ await expectLogic(logic).delay(1)++ logic.actions.resetUnavailableHomepage(urls.dashboard(99))+ await expectLogic(logic).delay(1)++ expect(logic.values.homepage?.pathname).toEqual(urls.dashboard(42))+ expect(removeProjectIdIfPresent(router.values.location.pathname)).toEqual(urls.dashboard(99))+ })++ // Clearing the setting is right wherever the homepage dashboard was found missing, but+ // navigating away is only right when that dashboard is what fills the screen.+ it('drops the homepage without navigating when it is missing from an embedded render', async () => {+ logic.actions.setHomepage(dashboardHomepage)+ router.actions.push(urls.notebook('abc'))+ await expectLogic(logic).delay(1)++ logic.actions.resetUnavailableHomepage(urls.dashboard(42))+ await expectLogic(logic).delay(1)++ expect(logic.values.homepage).toBeNull()+ expect(removeProjectIdIfPresent(router.values.location.pathname)).toEqual(urls.notebook('abc'))+ })+it('forwards allow-listed query params onto the homepage redirect and drops the rest', async () => {logic.actions.setHomepage(dashboardHomepage)router.actions.push(urls.projectHomepage(), { modal: 'feature', other: 'dropped' })diff --git a/frontend/src/scenes/sceneLogic.tsx b/frontend/src/scenes/sceneLogic.tsxindex ba03d791249b..aacfc631efeb 100644--- a/frontend/src/scenes/sceneLogic.tsx+++ b/frontend/src/scenes/sceneLogic.tsx@@ -92,6 +92,15 @@ const tabToPersistableSnapshot = (tab: SceneTab): SceneTab => {}}+// `/` and `/home` both resolve the configured homepage through this, so anything asking whether a+// location is the homepage has to derive it the same way.+const homepageTargetPathname = (homepage: SceneTab): string => {+ const targetPathname = addProjectIdIfMissing(homepage.pathname || urls.projectHomepage())+ return removeProjectIdIfPresent(targetPathname) === '/'+ ? addProjectIdIfMissing(urls.projectHomepage())+ : targetPathname+}+// Bootstrapped by Django into APP_CONTEXT so the configured homepage is known on first paint,// before any async fetch — otherwise urlToAction runs with a null homepage and /home can't redirect.const getBootstrappedHomepage = (): SceneTab | null => {@@ -307,6 +316,9 @@ export interface sceneLogicActions {reloadBrowserDueToImportError: () => {value: true}+ resetUnavailableHomepage: (pathname: string) => {+ pathname: string+ }setExportedScene: (exportedScene: SceneExport,sceneId: string,@@ -445,6 +457,7 @@ export const sceneLogic = kea<sceneLogicType>([reloadBrowserDueToImportError: true,setHomepage: (tab: SceneTab | null) => ({ tab }),+ resetUnavailableHomepage: (pathname: string) => ({ pathname }),}),reducers({sceneId: [@@ -692,6 +705,29 @@ export const sceneLogic = kea<sceneLogicType>([],}),listeners(({ values, actions, cache, props, selectors }) => ({+ // A homepage pointing at a deleted object answers every `/` and Home with a not-found screen,+ // and the picker that would change it sits behind that screen. Drop the setting instead.+ resetUnavailableHomepage: ({ pathname }) => {+ const target = addProjectIdIfMissing(pathname)+ if (!values.homepage || homepageTargetPathname(values.homepage) !== target) {+ return+ }+ actions.setHomepage(null)+ lemonToast.info('Your home pointed to something that no longer exists, so we reset it.')+ const location = router.values.currentLocation+ if (addProjectIdIfMissing(location.pathname) === target) {+ // Carry the hash and allow-listed params over, as the `/` → homepage redirect does,+ // so a modal bound to `?modal=` does not close on the way out.+ router.actions.replace(+ withForwardedHashAndSearchParams(+ urls.projectHomepage(),+ location.searchParams,+ location.hashParams,+ forwardedRedirectQueryParams+ )+ )+ }+ },setHomepage: ({ tab }) => {if (isSharedView()) {return@@ -1023,10 +1059,7 @@ export const sceneLogic = kea<sceneLogicType>([if (!homepage) {return false}- let targetPathname = addProjectIdIfMissing(homepage.pathname || urls.projectHomepage())- if (removeProjectIdIfPresent(targetPathname) === '/') {- targetPathname = addProjectIdIfMissing(urls.projectHomepage())- }+ const targetPathname = homepageTargetPathname(homepage)// Forward the incoming hash and allow-listed params (e.g. modal) onto the homepage, and// compare against that final target so a forwarded param can't loop.const target = withForwardedHashAndSearchParams(diff --git a/frontend/src/scenes/scenes.ts b/frontend/src/scenes/scenes.tsindex ca167a428e35..4e1bf28dcaab 100644--- a/frontend/src/scenes/scenes.ts+++ b/frontend/src/scenes/scenes.ts@@ -674,8 +674,16 @@ export const redirects: Record<'/me/settings': urls.settings('user'),'/new': urls.newTab(),'/live-debugger': urls.liveDebugger(),+ // Only billing, confirm-creation and create-project have an `/organization*` scene. Every other+ // path here is guessed or bookmarked, matched no route, and rendered the 404 screen.+ '/organization': urls.settings('organization'),'/organization/members': urls.settings('organization'),'/organization/settings': urls.settings('organization'),+ '/organization/projects': urls.settings('organization'),+ '/organization/settings/projects': urls.settings('organization'),+ '/organization/projects/new': urls.projectCreateFirst(),+ '/organization/create': urls.organizationCreateFirst(),+ '/organization/new': urls.organizationCreateFirst(),'/pipeline': urls.sources(),'/pipelines': urls.sources(),'/pipeline/new/site-app': urls.webScriptsNew(),