: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(desktop): derive the nav rail destination from the route (#87370)
Adam Leith12e6025b1c0f
diff --git a/products/desktop/packages/ui/src/features/canvas/components/ActivityView.tsx b/products/desktop/packages/ui/src/features/canvas/components/ActivityView.tsxindex d7ba26031b3f..1b23019985fe 100644--- a/products/desktop/packages/ui/src/features/canvas/components/ActivityView.tsx+++ b/products/desktop/packages/ui/src/features/canvas/components/ActivityView.tsx@@ -28,22 +28,12 @@ import { ActivityUnreadsToggle } from "@posthog/ui/features/canvas/components/Acimport { MentionText } from "@posthog/ui/features/canvas/components/MentionText";import { openActivityItem } from "@posthog/ui/features/canvas/components/openActivityItem";import { useBlockedTaskIds } from "@posthog/ui/features/canvas/hooks/useBlockedSessionCount";-import { useChannelsLayout } from "@posthog/ui/features/canvas/hooks/useChannelsLayout";import { useMarkTaskActivityRead } from "@posthog/ui/features/canvas/hooks/useMarkTaskActivityRead";import { useTaskActivity } from "@posthog/ui/features/canvas/hooks/useTaskActivity";import { useActivityFilterStore } from "@posthog/ui/features/canvas/stores/activityFilterStore";import { copyChannelLink } from "@posthog/ui/features/canvas/utils/copyChannelLink";import { useCommentNavigationStore } from "@posthog/ui/features/sessions/commentNavigationStore";import { DOT_TONE_VAR } from "@posthog/ui/features/sidebar/components/items/taskStatusVocabulary";-import {- PageHeader,- PageHeaderActions,- PageHeaderChip,- PageHeaderDescription,- PageHeaderHeading,- PageHeaderTitle,- PageHeaderTitleRow,-} from "@posthog/ui/primitives/PageHeader";import { track } from "@posthog/ui/shell/analytics";import { Text } from "@radix-ui/themes";import { useCallback, useEffect, useMemo } from "react";@@ -214,11 +204,14 @@ export function ActivityRow({);}-// The Activity page: every task the viewer is involved in — created, mentioned-// in, or messaged in — newest activity first. Rows clear as they are opened, not-// when the page is; merely landing here shouldn't dismiss what you haven't read.+// The Activity page for the code layout: every task the viewer is involved in —+// created, mentioned in, or messaged in — newest activity first. Rows clear as+// they are opened, not when the page is; merely landing here shouldn't dismiss+// what you haven't read.+//+// The spaces layout has no page: the feed is the column beside the rail+// (ChannelsSidebar) and /website/activity's pane is whatever you picked from it.export function ActivityView() {- const spacesLayout = useChannelsLayout();const client = useOptionalAuthenticatedClient();const { data: currentUser } = useCurrentUser({ client });const {@@ -312,7 +305,7 @@ export function ActivityView() {<EmptyDescription>{unreadsOnly? "You're all caught up."- : `Task updates and comment notifications across ${spacesLayout ? "spaces" : "channels"} appear here.`}+ : "Task updates and comment notifications across channels appear here."}</EmptyDescription></EmptyHeader></Empty>@@ -338,35 +331,6 @@ export function ActivityView() {</>);- if (spacesLayout) {- return (- <div className="flex h-full min-h-0 flex-col bg-gray-1">- <PageHeader>- <PageHeaderHeading>- <PageHeaderTitleRow>- <PageHeaderTitle>Activity</PageHeaderTitle>- {unreadCount > 0 && (- <PageHeaderChip icon={<BellIcon size={12} weight="fill" />}>- {unreadCount} unread- </PageHeaderChip>- )}- <PageHeaderActions>- {unreadCount > 0 && markAllReadButton}- <ActivityUnreadsToggle />- </PageHeaderActions>- </PageHeaderTitleRow>- <PageHeaderDescription>- Task updates and comment notifications across spaces.- </PageHeaderDescription>- </PageHeaderHeading>- </PageHeader>- <div className="min-h-0 flex-1 overflow-y-auto">- <div className="mx-auto w-full max-w-[680px] px-4 py-6">{feed}</div>- </div>- </div>- );- }-return (<div className="h-full overflow-y-auto bg-gray-1"><div className="mx-auto w-full max-w-[680px] px-4 py-6">@@ -376,8 +340,7 @@ export function ActivityView() {Activity</Text><Text size="2" className="block text-muted-foreground">- Task updates and comment notifications across{" "}- {spacesLayout ? "spaces" : "channels"}.+ Task updates and comment notifications across channels.</Text></div><div className="flex shrink-0 items-center gap-2">diff --git a/products/desktop/packages/ui/src/features/canvas/components/ChannelsSidebar.test.tsx b/products/desktop/packages/ui/src/features/canvas/components/ChannelsSidebar.test.tsxindex 84021bc3c453..cc7783f840e2 100644--- a/products/desktop/packages/ui/src/features/canvas/components/ChannelsSidebar.test.tsx+++ b/products/desktop/packages/ui/src/features/canvas/components/ChannelsSidebar.test.tsx@@ -17,6 +17,7 @@ const mocks = vi.hoisted(() => ({navigateToArchived: vi.fn(),track: vi.fn(),routeChannelId: undefined as string | undefined,+ routeId: "/website/$channelId/",markChannelSeen: vi.fn(),}));@@ -83,6 +84,11 @@ vi.mock("@posthog/ui/features/workspace/useWorkspace", () => ({}));vi.mock("@tanstack/react-router", () => ({useParams: () => ({ channelId: mocks.routeChannelId }),+ useRouterState: ({+ select,+ }: {+ select: (s: { matches: { routeId: string }[] }) => unknown;+ }) => select({ matches: [{ routeId: mocks.routeId }] }),}));import { PROJECT_BLUEBIRD_FLAG } from "@posthog/shared";@@ -130,6 +136,7 @@ describe("ChannelsSidebar", () => {mocks.archivedTaskIds = new Set();mocks.track.mockClear();mocks.routeChannelId = undefined;+ mocks.routeId = "/website/$channelId/";useCurrentChannelStore.setState({ currentChannelId: null });useChannelPaneStore.setState({ pane: "channel" });// hasUserSetOpen pins `open`, so the auto-open effect (which sees no@@ -153,6 +160,17 @@ describe("ChannelsSidebar", () => {mocks.channels = [ME, ENG];});+ // Activity owns this column whenever its route does, so the space tree can+ // never be what a reader finds under the Activity destination.+ it("hands the column to the activity feed on the Activity route", () => {+ mocks.routeChannelId = undefined;+ mocks.routeId = "/website/activity";+ renderSidebar();++ expect(screen.getByTestId("activity-feed")).toBeInTheDocument();+ expect(screen.queryByTestId("channels-list")).not.toBeInTheDocument();+ });+it("rests on the channel you're in", () => {mocks.routeChannelId = ENG.id;renderSidebar();diff --git a/products/desktop/packages/ui/src/features/canvas/components/NavRail.test.tsx b/products/desktop/packages/ui/src/features/canvas/components/NavRail.test.tsxindex e496a5df8411..2c51c4ecd036 100644--- a/products/desktop/packages/ui/src/features/canvas/components/NavRail.test.tsx+++ b/products/desktop/packages/ui/src/features/canvas/components/NavRail.test.tsx@@ -3,9 +3,10 @@ import userEvent from "@testing-library/user-event";import { beforeEach, describe, expect, it, vi } from "vitest";const mocks = vi.hoisted(() => ({- view: { type: "home" } as { type: string },- pathname: "/website/home",+ routeId: "/website/home",navigateToActivity: vi.fn(),+ navigateToCanvas: vi.fn(),+ navigateToChannel: vi.fn(),navigateToHome: vi.fn(),navigateToInbox: vi.fn(),}));@@ -14,8 +15,8 @@ vi.mock("@tanstack/react-router", () => ({useRouterState: ({select,}: {- select: (s: { location: { pathname: string } }) => unknown;- }) => select({ location: { pathname: mocks.pathname } }),+ select: (s: { matches: { routeId: string }[] }) => unknown;+ }) => select({ matches: [{ routeId: mocks.routeId }] }),}));vi.mock("@posthog/ui/features/canvas/hooks/useTaskActivity", () => ({@@ -28,17 +29,20 @@ vi.mock(vi.mock("@posthog/ui/features/feature-flags/useFeatureFlag", () => ({useFeatureFlag: () => false,}));+vi.mock("@posthog/ui/features/canvas/hooks/useChannelsLayout", () => ({+ useChannelsLayout: () => true,+}));vi.mock("@posthog/ui/features/inbox/hooks/useInboxAllReports", () => ({useInboxAllReports: () => ({ counts: { pulls: 0 } }),}));vi.mock("@posthog/ui/features/sidebar/components/ProjectSwitcher", () => ({ProjectSwitcher: () => null,}));-vi.mock("@posthog/ui/router/useAppView", () => ({- useAppView: () => mocks.view,-}));vi.mock("@posthog/ui/router/navigationBridge", () => ({+ getCurrentMatches: () => [{ routeId: mocks.routeId }],navigateToActivity: (...args: unknown[]) => mocks.navigateToActivity(...args),+ navigateToCanvas: (...args: unknown[]) => mocks.navigateToCanvas(...args),+ navigateToChannel: (...args: unknown[]) => mocks.navigateToChannel(...args),navigateToHome: (...args: unknown[]) => mocks.navigateToHome(...args),navigateToInbox: (...args: unknown[]) => mocks.navigateToInbox(...args),navigateToLoops: vi.fn(),@@ -49,87 +53,91 @@ vi.mock("@posthog/ui/features/canvas/components/ActivityHoverCard", () => ({ActivityHoverCard: () => <div>Recent activity card</div>,}));-import { useChannelPaneStore } from "@posthog/ui/features/canvas/stores/channelPaneStore";+import {+ clearKeepListForRoute,+ shouldKeepListForRoute,+ useChannelPaneStore,+} from "@posthog/ui/features/canvas/stores/channelPaneStore";import { useCurrentChannelStore } from "@posthog/ui/features/canvas/stores/currentChannelStore";-import { useNavRailStore } from "@posthog/ui/features/canvas/stores/navRailStore";import { useSidebarStore } from "@posthog/ui/features/sidebar/sidebarStore";import { NavRail } from "./NavRail";describe("NavRail", () => {beforeEach(() => {vi.clearAllMocks();- mocks.view = { type: "home" };- mocks.pathname = "/website/home";- useNavRailStore.setState({ pane: "spaces" });+ mocks.routeId = "/website/home";useSidebarStore.setState({ navItemOverrides: {}, navItemOrder: [] });useCurrentChannelStore.setState({ currentChannelId: null });useChannelPaneStore.setState({ pane: "channel" });+ clearKeepListForRoute();});- it("hands the sidebar column to Activity without leaving the current screen", async () => {- const user = userEvent.setup();+ // The route is the whole answer, so a destination can never be lit over a+ // screen that isn't it.+ it.each([+ ["/website/home", "Home"],+ ["/website/activity", "Activity"],+ ["/code/inbox/pulls/$reportId", "Inbox"],+ ["/website/command-center", "Command Center"],+ ["/website/$channelId/loops", "Spaces"],+ ["/website/$channelId/context", "Spaces"],+ ["/website/$channelId/", "Spaces"],+ ["/website/$channelId/tasks/$taskId", "Spaces"],+ ])("lights %s as %s", (routeId, label) => {+ mocks.routeId = routeId;render(<NavRail />);- await user.click(screen.getByLabelText("Activity"));-- expect(useNavRailStore.getState().pane).toBe("activity");- expect(mocks.navigateToActivity).not.toHaveBeenCalled();- expect(mocks.navigateToHome).not.toHaveBeenCalled();- expect(mocks.navigateToInbox).not.toHaveBeenCalled();+ expect(screen.getByLabelText(label)).toHaveAttribute(+ "data-selected",+ "true",+ );});- it("moves into the space tree when Activity is picked from outside it", async () => {+ it("routes to Activity from a screen that has no column for it", async () => {const user = userEvent.setup();- mocks.pathname = "/code/inbox";- mocks.view = { type: "inbox" };+ mocks.routeId = "/code/inbox";render(<NavRail />);await user.click(screen.getByLabelText("Activity"));- expect(useNavRailStore.getState().pane).toBe("activity");expect(mocks.navigateToActivity).toHaveBeenCalledOnce();});- it("shows the space tree without routing to a space", async () => {+ it("leaves a whole-screen destination for the space it was scoped to", async () => {const user = userEvent.setup();- mocks.view = { type: "activity" };+ useCurrentChannelStore.setState({ currentChannelId: "chan-1" });render(<NavRail />);await user.click(screen.getByLabelText("Spaces"));- expect(useNavRailStore.getState().pane).toBe("spaces");- expect(mocks.navigateToHome).not.toHaveBeenCalled();+ expect(mocks.navigateToChannel).toHaveBeenCalledWith("chan-1");+ // Arriving at the space would otherwise slide straight past the list the+ // pick asked for.+ expect(shouldKeepListForRoute("chan-1")).toBe(true);+ expect(useChannelPaneStore.getState().pane).toBe("list");});- it("slides back to the list when a space is already open", async () => {+ it("falls back to the space index when nothing is scoped", async () => {const user = userEvent.setup();- useChannelPaneStore.setState({ pane: "channel" });render(<NavRail />);await user.click(screen.getByLabelText("Spaces"));- expect(useChannelPaneStore.getState().pane).toBe("list");+ expect(mocks.navigateToCanvas).toHaveBeenCalledOnce();+ expect(mocks.navigateToChannel).not.toHaveBeenCalled();});- it("keeps a route-free pick from snapping back to the route behind it", async () => {+ it("only slides back to the list when a space is already on screen", async () => {const user = userEvent.setup();- const { rerender } = render(<NavRail />);+ mocks.routeId = "/website/$channelId/tasks/$taskId";+ useCurrentChannelStore.setState({ currentChannelId: "chan-1" });+ render(<NavRail />);await user.click(screen.getByLabelText("Spaces"));- rerender(<NavRail />);-- expect(useNavRailStore.getState().pane).toBe("spaces");- });-- it("follows the route when the route is what moved", () => {- mocks.view = { type: "activity" };- render(<NavRail />);- expect(useNavRailStore.getState().pane).toBe("activity");- expect(screen.getByLabelText("Activity")).toHaveAttribute(- "data-selected",- "true",- );+ expect(useChannelPaneStore.getState().pane).toBe("list");+ expect(mocks.navigateToChannel).not.toHaveBeenCalled();+ expect(mocks.navigateToCanvas).not.toHaveBeenCalled();});it("peeks at the feed on hover while Activity is somewhere else", async () => {@@ -145,7 +153,7 @@ describe("NavRail", () => {it("drops the peek once Activity is the destination", async () => {const user = userEvent.setup();- mocks.view = { type: "activity" };+ mocks.routeId = "/website/activity";render(<NavRail />);const bell = screen.getByLabelText("Activity");@@ -199,23 +207,6 @@ describe("NavRail", () => {]);});- // Two routes can share a destination, so the pane it derives does not change- // between them. Moving from one to the other still has to leave Activity.- it("leaves Activity when the route moves inside the space it was over", async () => {- const user = userEvent.setup();- mocks.pathname = "/website/chan-1/tasks/task-a";- mocks.view = { type: "task-detail" };- const { rerender } = render(<NavRail />);-- await user.click(screen.getByLabelText("Activity"));- expect(useNavRailStore.getState().pane).toBe("activity");-- mocks.pathname = "/website/chan-1/tasks/task-b";- rerender(<NavRail />);-- expect(useNavRailStore.getState().pane).toBe("spaces");- });-it("lights the last square of the Spaces mark while a space is open", () => {useCurrentChannelStore.setState({ currentChannelId: "chan-1" });useChannelPaneStore.setState({ pane: "channel" });@@ -230,15 +221,4 @@ describe("NavRail", () => {expect(lit()).toBe(0);});-- it("counts a channel or task as part of Spaces", () => {- mocks.view = { type: "task-detail" };- render(<NavRail />);-- expect(screen.getByLabelText("Spaces")).toHaveAttribute(- "data-selected",- "true",- );- expect(screen.getByLabelText("Home")).not.toHaveAttribute("data-selected");- });});diff --git a/products/desktop/packages/ui/src/features/canvas/components/NavRail.tsx b/products/desktop/packages/ui/src/features/canvas/components/NavRail.tsxindex 7bb4c237e99f..dffe3ebb9565 100644--- a/products/desktop/packages/ui/src/features/canvas/components/NavRail.tsx+++ b/products/desktop/packages/ui/src/features/canvas/components/NavRail.tsx@@ -14,13 +14,12 @@ import { LOOPS_FLAG } from "@posthog/shared";import { ANALYTICS_EVENTS } from "@posthog/shared/analytics-events";import { ActivityHoverCard } from "@posthog/ui/features/canvas/components/ActivityHoverCard";import {- paneForView,type RailCounts,type RailDestination,visibleRailDestinations,} from "@posthog/ui/features/canvas/components/railDestinations";+import { useRailPane } from "@posthog/ui/features/canvas/hooks/useRailSurface";import { useTaskActivity } from "@posthog/ui/features/canvas/hooks/useTaskActivity";-import { useNavRailStore } from "@posthog/ui/features/canvas/stores/navRailStore";import { useCommandCenterActiveCount } from "@posthog/ui/features/command-center/useCommandCenterActiveCount";import { useFeatureFlag } from "@posthog/ui/features/feature-flags/useFeatureFlag";import { useInboxAllReports } from "@posthog/ui/features/inbox/hooks/useInboxAllReports";@@ -32,15 +31,11 @@ import {} from "@posthog/ui/features/sidebar/constants";import { useSidebarStore } from "@posthog/ui/features/sidebar/sidebarStore";import { CountBadge } from "@posthog/ui/primitives/CountBadge";-import { useAppView } from "@posthog/ui/router/useAppView";import { track } from "@posthog/ui/shell/analytics";-import { useRouterState } from "@tanstack/react-router";import {type ComponentPropsWithRef,type ReactElement,type ReactNode,- useEffect,- useRef,useState,} from "react";@@ -175,7 +170,6 @@ function ActivityNavItem({* that sidebar leaves the destinations reachable.*/export function NavRail() {- const view = useAppView();const loopsEnabled = useFeatureFlag(LOOPS_FLAG, import.meta.env.DEV);const { counts: inboxCounts } = useInboxAllReports({@@ -189,10 +183,9 @@ export function NavRail() {activity: unseenActivity,commandCenter: commandCenterCount,};- const railPane = useNavRailStore((s) => s.pane);- const setRailPane = useNavRailStore((s) => s.setPane);- const pathname = useRouterState({ select: (s) => s.location.pathname });- const inWebsiteTree = pathname.startsWith("/website");+ // The route is the only thing that says where you are, so the rail cannot+ // light a destination the screen isn't on.+ const railPane = useRailPane();const navItemOverrides = useSidebarStore((s) => s.navItemOverrides);const navItemOrder = useSidebarStore((s) => s.navItemOrder);const destinations = visibleRailDestinations({@@ -203,29 +196,16 @@ export function NavRail() {const settingsVisible = isNavItemVisible(navItemOverrides, "configure");const pick =- ({ pane, analyticsId, onPick }: RailDestination) =>+ ({ analyticsId, onPick }: RailDestination) =>() => {track(ANALYTICS_EVENTS.SIDEBAR_NAV_ITEM_CLICKED, {item: analyticsId,in_more: false,layout: "channels",});- setRailPane(pane);- onPick?.({ inWebsiteTree });+ onPick();};- // Keyed on the path, not on the pane it derives: two routes can share a- // destination, and a move between them still has to pull the rail off- // Activity. Not keyed on every render either, or picking Spaces or Activity- // would snap straight back to the screen behind them.- const routePane = paneForView(view.type);- const lastPathRef = useRef<string | null>(null);- useEffect(() => {- if (lastPathRef.current === pathname) return;- lastPathRef.current = pathname;- setRailPane(routePane);- }, [pathname, routePane, setRailPane]);-return (// One provider for the whole rail: the tooltip skip window is provider// state, so isolated providers never share it.diff --git a/products/desktop/packages/ui/src/features/canvas/components/SpaceHeaderRow.test.tsx b/products/desktop/packages/ui/src/features/canvas/components/SpaceHeaderRow.test.tsxindex 6246270623d7..f897b82de978 100644--- a/products/desktop/packages/ui/src/features/canvas/components/SpaceHeaderRow.test.tsx+++ b/products/desktop/packages/ui/src/features/canvas/components/SpaceHeaderRow.test.tsx@@ -30,14 +30,22 @@ vi.mock("@posthog/host-router/react", () => ({}));vi.mock("@posthog/ui/shell/analytics", () => ({ track: vi.fn() }));vi.mock("@tanstack/react-router", () => ({- Outlet: () => null,+ // The route's own pane, which is where the header's writer lives.+ Outlet: () => <ActivityDetailPane />,useNavigate: () => vi.fn(),- useParams: () => ({}),+ useParams: () => ({ channelId: "chan-1", taskId: "task-1" }),useRouterState: ({select,}: {- select: (s: { location: { pathname: string } }) => string;- }) => select({ location: { pathname: "/website/home" } }),+ select: (s: {+ location: { pathname: string };+ matches: { routeId: string }[];+ }) => unknown;+ }) =>+ select({+ location: { pathname: "/website/chan-1/tasks/task-1" },+ matches: [{ routeId: "/website/$channelId/tasks/$taskId" }],+ }),}));vi.mock("@posthog/ui/features/task-detail/components/TaskHeaderActions",@@ -109,15 +117,14 @@ vi.mock("@posthog/ui/features/task-detail/components/TaskDetail", () => ({}));import { useActivityDetailStore } from "@posthog/ui/features/canvas/stores/activityDetailStore";-import { useNavRailStore } from "@posthog/ui/features/canvas/stores/navRailStore";import { useSetHeaderContent } from "@posthog/ui/hooks/useSetHeaderContent";+import { ActivityDetailPane } from "./ActivityDetailPane";import { WebsiteLayout } from "./WebsiteLayout";describe("SpaceHeaderRow", () => {it("keeps the header store off the layout that renders its writer", () => {- useNavRailStore.setState({ pane: "activity" });useActivityDetailStore.setState({- selected: { id: "a1", taskId: "task-1", channelId: "chan-1" } as never,+ selected: { id: "a1", taskId: "task-1", channelId: "chan-1" },});const client = new QueryClient({defaultOptions: { queries: { retry: false } },diff --git a/products/desktop/packages/ui/src/features/canvas/components/WebsiteLayout.test.tsx b/products/desktop/packages/ui/src/features/canvas/components/WebsiteLayout.test.tsxindex b6d7a57fbf60..50435b49ac93 100644--- a/products/desktop/packages/ui/src/features/canvas/components/WebsiteLayout.test.tsx+++ b/products/desktop/packages/ui/src/features/canvas/components/WebsiteLayout.test.tsx@@ -29,8 +29,15 @@ vi.mock("@tanstack/react-router", () => ({useRouterState: ({select,}: {- select: (s: { location: { pathname: string } }) => string;- }) => select({ location: { pathname: usePathname() } }),+ select: (s: {+ location: { pathname: string };+ matches: { routeId: string }[];+ }) => unknown;+ }) =>+ select({+ location: { pathname: usePathname() },+ matches: [{ routeId: "/website/$channelId/tasks/$taskId" }],+ }),}));vi.mock(diff --git a/products/desktop/packages/ui/src/features/canvas/components/WebsiteLayout.tsx b/products/desktop/packages/ui/src/features/canvas/components/WebsiteLayout.tsxindex 08c53e908035..b46a9821fe30 100644--- a/products/desktop/packages/ui/src/features/canvas/components/WebsiteLayout.tsx+++ b/products/desktop/packages/ui/src/features/canvas/components/WebsiteLayout.tsx@@ -24,7 +24,6 @@ import {DropdownMenuTrigger,} from "@posthog/quill";import { ANALYTICS_EVENTS } from "@posthog/shared/analytics-events";-import { ActivityDetailPane } from "@posthog/ui/features/canvas/components/ActivityDetailPane";import { ChannelBreadcrumb } from "@posthog/ui/features/canvas/components/ChannelBreadcrumb";import { iconForTemplate } from "@posthog/ui/features/canvas/components/canvasTemplateIcon";import { NewCanvasMenu } from "@posthog/ui/features/canvas/components/NewCanvasMenu";@@ -42,7 +41,6 @@ import {useDashboard,useDashboardMutations,} from "@posthog/ui/features/canvas/hooks/useDashboards";-import { useRailSurface } from "@posthog/ui/features/canvas/hooks/useRailSurface";import { useCanvasChatPanelStore } from "@posthog/ui/features/canvas/stores/canvasChatPanelStore";import {useDashboardEditStore,@@ -357,9 +355,8 @@ export function WebsiteLayout() {const channelId = params.channelId;const dashboardId = params.dashboardId;- // Activity reads a task into this pane without routing, so the session is- // not always the one in the URL.- const { showsActivityDetail } = useRailSurface();+ // Activity reads a task into its pane off the feed, so the session is not+ // always the one in the URL.const { taskId, channelId: taskChannelId } = useActiveSession();const rightPanelOpen = useRightPanelOpen(taskId);@@ -456,7 +453,7 @@ export function WebsiteLayout() {it. */}<div className="isolate min-w-0 flex-1 overflow-hidden"><MentionAvailabilityProvider disabledReason={mentionsDisabledReason}>- {showsActivityDetail ? <ActivityDetailPane /> : <Outlet />}+ <Outlet /></MentionAvailabilityProvider></div>{/* One panel at a time at the right of the content: the session'sdiff --git a/products/desktop/packages/ui/src/features/canvas/components/railDestinations.ts b/products/desktop/packages/ui/src/features/canvas/components/railDestinations.tsindex 4c1e86efb5b8..d8b6a00d6b17 100644--- a/products/desktop/packages/ui/src/features/canvas/components/railDestinations.ts+++ b/products/desktop/packages/ui/src/features/canvas/components/railDestinations.ts@@ -7,8 +7,15 @@ import {} from "@phosphor-icons/react";import type { SidebarNavItem } from "@posthog/shared/analytics-events";import { SpacesIcon } from "@posthog/ui/features/canvas/components/SpacesIcon";-import { showChannelList } from "@posthog/ui/features/canvas/stores/channelPaneStore";-import type { NavRailPane } from "@posthog/ui/features/canvas/stores/navRailStore";+import {+ getRailPane,+ type NavRailPane,+} from "@posthog/ui/features/canvas/railPane";+import {+ keepListForRoute,+ showChannelList,+} from "@posthog/ui/features/canvas/stores/channelPaneStore";+import { useCurrentChannelStore } from "@posthog/ui/features/canvas/stores/currentChannelStore";import {formatHotkey,SHORTCUTS,@@ -22,12 +29,13 @@ import type { CountBadgeTone } from "@posthog/ui/primitives/CountBadge";import { LoopIcon } from "@posthog/ui/primitives/LoopIcon";import {navigateToActivity,+ navigateToCanvas,+ navigateToChannel,navigateToHome,navigateToInbox,navigateToLoops,navigateToWebsiteCommandCenter,} from "@posthog/ui/router/navigationBridge";-import type { AppViewType } from "@posthog/ui/router/useAppView";import type { ComponentType } from "react";export interface RailCounts {@@ -41,8 +49,9 @@ export interface RailDestination {label: string;analyticsId: SidebarNavItem;Icon: ComponentType<IconProps>;- viewTypes: readonly AppViewType[];- onPick?: (ctx: { inWebsiteTree: boolean }) => void;+ /** Every pick routes. The rail's selected state is read back off the route,+ * so a destination that changed nothing in the URL could never be left. */+ onPick: () => void;customizableId?: CustomizableNavItemId;shortcut?: string;count?: (counts: RailCounts) => number;@@ -50,13 +59,32 @@ export interface RailDestination {enabled?: (flags: { loops: boolean }) => boolean;}+/**+ * Show the space tree. Which space you are in is unchanged — browsing the list+ * is view state — but the destinations that own the whole screen have no column+ * to put it in, so leaving one is part of the pick.+ */+export function showSpaces(): void {+ showChannelList();+ if (getRailPane() === "spaces") return;++ const channelId = useCurrentChannelStore.getState().currentChannelId;+ if (!channelId) {+ navigateToCanvas();+ return;+ }+ // Arriving at a space pulls the slider to that space. This pick asked for the+ // list, so latch it across the navigation it is about to make.+ keepListForRoute(channelId);+ navigateToChannel(channelId);+}+export const RAIL_DESTINATIONS: readonly RailDestination[] = [{pane: "home",label: "Home",analyticsId: "home",Icon: HouseSimple,- viewTypes: ["home"],onPick: navigateToHome,},{@@ -64,8 +92,7 @@ export const RAIL_DESTINATIONS: readonly RailDestination[] = [label: "Spaces",analyticsId: "spaces",Icon: SpacesIcon,- viewTypes: [],- onPick: showChannelList,+ onPick: showSpaces,},{pane: "activity",@@ -73,10 +100,7 @@ export const RAIL_DESTINATIONS: readonly RailDestination[] = [label: "Activity",analyticsId: "activity",Icon: BellIcon,- viewTypes: ["activity"],- onPick: ({ inWebsiteTree }) => {- if (!inWebsiteTree) navigateToActivity();- },+ onPick: navigateToActivity,count: (counts) => counts.activity,},{@@ -85,7 +109,6 @@ export const RAIL_DESTINATIONS: readonly RailDestination[] = [label: "Inbox",analyticsId: "inbox",Icon: EnvelopeSimple,- viewTypes: ["inbox"],onPick: navigateToInbox,shortcut: formatHotkey(SHORTCUTS.INBOX),count: (counts) => counts.inbox,@@ -96,7 +119,6 @@ export const RAIL_DESTINATIONS: readonly RailDestination[] = [label: "Command Center",analyticsId: "command_center",Icon: Lightning,- viewTypes: ["command-center"],onPick: navigateToWebsiteCommandCenter,count: (counts) => counts.commandCenter,countTone: "neutral",@@ -107,23 +129,11 @@ export const RAIL_DESTINATIONS: readonly RailDestination[] = [label: "Loops",analyticsId: "loops",Icon: LoopIcon,- viewTypes: ["loops"],onPick: () => navigateToLoops(),enabled: (flags) => flags.loops,},];-const PANE_BY_VIEW_TYPE = new Map<AppViewType, NavRailPane>(- RAIL_DESTINATIONS.flatMap((destination) =>- destination.viewTypes.map((viewType) => [viewType, destination.pane]),- ),-);--/** Which destination a route belongs to. Unclaimed routes belong to Spaces. */-export function paneForView(viewType: AppViewType): NavRailPane {- return PANE_BY_VIEW_TYPE.get(viewType) ?? "spaces";-}-// Deliberately not the shared `orderedNavItems`: its adjacency rule pins// Activity below Inbox, and the rail puts Activity first.export function visibleRailDestinations({diff --git a/products/desktop/packages/ui/src/features/canvas/grid/WebsiteHome.tsx b/products/desktop/packages/ui/src/features/canvas/grid/WebsiteHome.tsxindex 6e2131747826..d1d9653fc9dc 100644--- a/products/desktop/packages/ui/src/features/canvas/grid/WebsiteHome.tsx+++ b/products/desktop/packages/ui/src/features/canvas/grid/WebsiteHome.tsx@@ -88,7 +88,7 @@ export function WebsiteHome() {}return (<div className="flex h-full flex-col">- <div className="flex shrink-0 items-center justify-between border-(--gray-4) border-b px-4 py-2">+ <div className="flex shrink-0 items-center justify-between border-border border-b px-4 py-2"><Heading size="lg" className="font-bold">Home</Heading>diff --git a/products/desktop/packages/ui/src/features/canvas/hooks/useRailSurface.ts b/products/desktop/packages/ui/src/features/canvas/hooks/useRailSurface.tsindex c8e7ddb68dff..98854ed83ffc 100644--- a/products/desktop/packages/ui/src/features/canvas/hooks/useRailSurface.ts+++ b/products/desktop/packages/ui/src/features/canvas/hooks/useRailSurface.ts@@ -1,9 +1,10 @@import { useChannelsLayout } from "@posthog/ui/features/canvas/hooks/useChannelsLayout";import {type NavRailPane,+ railPaneForMatches,railPaneHasSidebar,- useNavRailStore,-} from "@posthog/ui/features/canvas/stores/navRailStore";+} from "@posthog/ui/features/canvas/railPane";+import { useRouterState } from "@tanstack/react-router";export interface RailSurface {pane: NavRailPane;@@ -11,11 +12,17 @@ export interface RailSurface {showsActivityDetail: boolean;}+/** The rail destination the route names. A string, so the selector's result is+ * stable and unrelated route changes don't re-render every consumer. */+export function useRailPane(): NavRailPane {+ return useRouterState({ select: (s) => railPaneForMatches(s.matches) });+}+/** What the rail is putting on screen. The one answer, for all three surfaces* that need it. */export function useRailSurface(): RailSurface {const channelsLayout = useChannelsLayout();- const pane = useNavRailStore((s) => s.pane);+ const pane = useRailPane();return {pane,diff --git a/products/desktop/packages/ui/src/features/canvas/railPane.test.ts b/products/desktop/packages/ui/src/features/canvas/railPane.test.tsnew file mode 100644index 000000000000..8097a12f289e--- /dev/null+++ b/products/desktop/packages/ui/src/features/canvas/railPane.test.ts@@ -0,0 +1,46 @@+import { describe, expect, it } from "vitest";+import { railPaneForRouteId, railPaneHasSidebar } from "./railPane";++describe("railPaneForRouteId", () => {+ it.each([+ ["/website/home", "home"],+ ["/website/activity", "activity"],+ ["/website/command-center", "command-center"],+ ["/command-center", "command-center"],+ ["/code/inbox", "inbox"],+ ["/code/inbox/pulls/$reportId", "inbox"],+ ["/code/loops", "loops"],+ ["/code/loops/$loopId/edit", "loops"],+ ] as const)("puts %s on %s", (routeId, pane) => {+ expect(railPaneForRouteId(routeId)).toBe(pane);+ });++ // A space page is a space page whatever it is called. The lookalikes are the+ // reason this matches route ids rather than path text.+ it.each([+ "/website/",+ "/website/$channelId/",+ "/website/$channelId/loops",+ "/website/$channelId/context",+ "/website/$channelId/history",+ "/website/$channelId/canvases",+ "/website/$channelId/tasks/$taskId",+ "/website/feeds/$feedId",+ "/code/tasks/$taskId",+ ])("leaves %s with Spaces", (routeId) => {+ expect(railPaneForRouteId(routeId)).toBe("spaces");+ });+});++describe("railPaneHasSidebar", () => {+ it.each(["home", "inbox", "command-center", "loops"] as const)(+ "gives %s the whole screen",+ (pane) => {+ expect(railPaneHasSidebar(pane)).toBe(false);+ },+ );++ it.each(["spaces", "activity"] as const)("gives %s a column", (pane) => {+ expect(railPaneHasSidebar(pane)).toBe(true);+ });+});diff --git a/products/desktop/packages/ui/src/features/canvas/railPane.ts b/products/desktop/packages/ui/src/features/canvas/railPane.tsnew file mode 100644index 000000000000..16b5f3a01524--- /dev/null+++ b/products/desktop/packages/ui/src/features/canvas/railPane.ts@@ -0,0 +1,60 @@+import { getCurrentMatches } from "@posthog/ui/router/navigationBridge";++/**+ * Which rail destination the app is on, and whether that destination owns the+ * column beside the rail.+ *+ * The route is the only input. A destination the user could be "on" without the+ * URL saying so is what let the sidebar and the screen disagree — Home wearing+ * the space list, Activity drawn twice, a space page with no space nav.+ */+export type NavRailPane =+ | "home"+ | "spaces"+ | "activity"+ | "inbox"+ | "command-center"+ | "loops";++/**+ * Route id prefixes each destination claims. Matched against the deepest route+ * in the match chain, so a destination claims its whole subtree (/code/inbox+ * covers /code/inbox/pulls/$reportId) without claiming a lookalike elsewhere+ * (/code/loops never covers /website/$channelId/loops).+ */+const PANE_BY_ROUTE_PREFIX: readonly (readonly [string, NavRailPane])[] = [+ ["/website/home", "home"],+ ["/website/activity", "activity"],+ ["/website/command-center", "command-center"],+ ["/command-center", "command-center"],+ ["/code/inbox", "inbox"],+ ["/code/loops", "loops"],+];++/** Unclaimed routes belong to Spaces — the app's resting destination. */+export function railPaneForRouteId(routeId: string): NavRailPane {+ for (const [prefix, pane] of PANE_BY_ROUTE_PREFIX) {+ if (routeId === prefix || routeId.startsWith(`${prefix}/`)) return pane;+ }+ return "spaces";+}++export function railPaneForMatches(+ matches: readonly { routeId: string }[],+): NavRailPane {+ return railPaneForRouteId(matches[matches.length - 1]?.routeId ?? "");+}++/** Read the destination outside React (event handlers, imperative picks). */+export function getRailPane(): NavRailPane {+ return railPaneForMatches(getCurrentMatches());+}++// Home, Inbox, Command Center and Loops are whole-screen destinations: no+// route under them may put a second nav on the screen. Spaces owns the space+// tree, Activity owns the feed.+const PANES_WITH_SIDEBAR = new Set<NavRailPane>(["spaces", "activity"]);++export function railPaneHasSidebar(pane: NavRailPane): boolean {+ return PANES_WITH_SIDEBAR.has(pane);+}diff --git a/products/desktop/packages/ui/src/features/canvas/stores/navRailStore.ts b/products/desktop/packages/ui/src/features/canvas/stores/navRailStore.tsdeleted file mode 100644index 64b07d87ae2d..000000000000--- a/products/desktop/packages/ui/src/features/canvas/stores/navRailStore.ts+++ /dev/null@@ -1,29 +0,0 @@-import { create } from "zustand";--/**- * Which rail destination is selected. Only Spaces and Activity own the column- * beside the rail; the rest are whole-screen and collapse it away.- */-export type NavRailPane =- | "home"- | "spaces"- | "activity"- | "inbox"- | "command-center"- | "loops";--const PANES_WITH_SIDEBAR = new Set<NavRailPane>(["spaces", "activity"]);--export function railPaneHasSidebar(pane: NavRailPane): boolean {- return PANES_WITH_SIDEBAR.has(pane);-}--interface NavRailState {- pane: NavRailPane;- setPane: (pane: NavRailPane) => void;-}--export const useNavRailStore = create<NavRailState>()((set) => ({- pane: "spaces",- setPane: (pane) => set({ pane }),-}));diff --git a/products/desktop/packages/ui/src/features/navigation/useReviewInRightPanel.test.ts b/products/desktop/packages/ui/src/features/navigation/useReviewInRightPanel.test.tsindex dfe4e063858f..24a049a2a294 100644--- a/products/desktop/packages/ui/src/features/navigation/useReviewInRightPanel.test.ts+++ b/products/desktop/packages/ui/src/features/navigation/useReviewInRightPanel.test.ts@@ -4,6 +4,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest";const mocks = vi.hoisted(() => ({channelsLayout: true,routeParams: {} as { taskId?: string; channelId?: string },+ routeId: "/website/$channelId/tasks/$taskId",}));vi.mock("@posthog/ui/features/canvas/hooks/useChannelsLayout", () => ({@@ -11,17 +12,21 @@ vi.mock("@posthog/ui/features/canvas/hooks/useChannelsLayout", () => ({}));vi.mock("@tanstack/react-router", () => ({useParams: () => mocks.routeParams,+ useRouterState: ({+ select,+ }: {+ select: (s: { matches: { routeId: string }[] }) => unknown;+ }) => select({ matches: [{ routeId: mocks.routeId }] }),}));import { useActivityDetailStore } from "@posthog/ui/features/canvas/stores/activityDetailStore";-import { useNavRailStore } from "@posthog/ui/features/canvas/stores/navRailStore";import { useReviewInRightPanel } from "./useReviewInRightPanel";describe("useReviewInRightPanel", () => {beforeEach(() => {mocks.channelsLayout = true;mocks.routeParams = {};- useNavRailStore.setState({ pane: "spaces" });+ mocks.routeId = "/website/$channelId/tasks/$taskId";useActivityDetailStore.setState({ selected: null });});@@ -33,7 +38,7 @@ describe("useReviewInRightPanel", () => {// The regression: no channel in the URL left both surfaces drawing the diff.it("hands it over for a task read from the activity feed too", () => {- useNavRailStore.setState({ pane: "activity" });+ mocks.routeId = "/website/activity";useActivityDetailStore.setState({selected: { id: "a1", taskId: "task-1", channelId: null },});diff --git a/products/desktop/packages/ui/src/router/routes/website/activity.tsx b/products/desktop/packages/ui/src/router/routes/website/activity.tsxindex bdeb495d595e..3091251e60a1 100644--- a/products/desktop/packages/ui/src/router/routes/website/activity.tsx+++ b/products/desktop/packages/ui/src/router/routes/website/activity.tsx@@ -1,9 +1,18 @@+import { ActivityDetailPane } from "@posthog/ui/features/canvas/components/ActivityDetailPane";import { ActivityView } from "@posthog/ui/features/canvas/components/ActivityView";+import { useChannelsLayout } from "@posthog/ui/features/canvas/hooks/useChannelsLayout";import { createFileRoute } from "@tanstack/react-router";-// Channels-space Activity page: every task the viewer is involved in — created,-// @-mentioned in, or messaged in — across channels. The sidebar's Activity nav-// badge counts what's new here.+// Activity: every task the viewer is involved in — created, @-mentioned in, or+// messaged in — across spaces. The rail's Activity badge counts what's new here.export const Route = createFileRoute("/website/activity")({- component: ActivityView,+ component: ActivityRoute,});++function ActivityRoute() {+ // Under the spaces layout the feed is the sidebar column (ChannelsSidebar+ // draws it for this route), so the pane beside it is whatever you picked from+ // the feed. Without that layout there is no such column and the page has to+ // carry the feed itself.+ return useChannelsLayout() ? <ActivityDetailPane /> : <ActivityView />;+}