Skip to content

: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.

fix(desktop): name the canvases tab after the page and its canvas (#103762)

Shy Altered66f2e1df1f
diff --git a/products/desktop/packages/ui/src/features/browser-tabs/AGENTS.md b/products/desktop/packages/ui/src/features/browser-tabs/AGENTS.md
index 94bdc544ee21..09501cb6ffed 100644
--- a/products/desktop/packages/ui/src/features/browser-tabs/AGENTS.md
+++ b/products/desktop/packages/ui/src/features/browser-tabs/AGENTS.md
@@ -275,6 +275,11 @@ retarget its originating background tab as described below. `railHistoryStore`
`useActiveSession()`, never `params.taskId`, or a tab sitting on an open
session reads "New tab". That selection lives in the URL precisely so a tab
can name it and restore it — don't move it back into a store.
+- **A canvas is not always a path param either.** `/canvases` keeps the open
+ canvas in its *search* (`?canvas=`), so the strip folds that id together with
+ `params.dashboardId` into one `routeCanvasId`. The identity, the label and the
+ name lookup all read that value. Without it the page has no label of its own
+ and the tab keeps the name of the page you came from.
- **A saved search names its own tab.** `/feeds/$feedId` is the tab; picking a
result reads that task into the pane without leaving the search, so the strip
drops the active session there and labels the tab with the search's name.
diff --git a/products/desktop/packages/ui/src/features/browser-tabs/BrowserTabStrip.tsx b/products/desktop/packages/ui/src/features/browser-tabs/BrowserTabStrip.tsx
index 93adf98a0f67..b5fa5239b8f1 100644
--- a/products/desktop/packages/ui/src/features/browser-tabs/BrowserTabStrip.tsx
+++ b/products/desktop/packages/ui/src/features/browser-tabs/BrowserTabStrip.tsx
@@ -28,6 +28,7 @@ import {
} from "@posthog/ui/features/canvas/hooks/useDashboards";
import { useProjectTaskFeeds } from "@posthog/ui/features/canvas/hooks/useProjectTaskFeeds";
import { useRailPane } from "@posthog/ui/features/canvas/hooks/useRailSurface";
+import { useSelectedCanvasId } from "@posthog/ui/features/canvas/hooks/useSelectedCanvasId";
import { isRestorableVisitHref } from "@posthog/ui/features/canvas/railPane";
import {
activityReportIdFromHref,
@@ -161,6 +162,11 @@ function BrowserTabStripImpl() {
reportId?: string;
};
const routeFeedId = params.feedId ?? null;
+ // The canvases page names its open canvas in its SEARCH, not in a path
+ // param, so fold the two sources into one id. Without this the tab keeps
+ // whatever label it had before you picked a canvas.
+ const selectedCanvasId = useSelectedCanvasId();
+ const routeCanvasId = params.dashboardId ?? selectedCanvasId ?? null;
const pathname = useRouterState({ select: (s) => s.location.pathname });
// What the effect reconciles against: the settled href and the tab that entry
// belongs to, read from one snapshot (see settledLocation for why that
@@ -266,7 +272,7 @@ function BrowserTabStripImpl() {
// Only poll the all-tasks list when a task tab actually needs a title.
const hasTaskTab = snapshot.tabs.some((t) => t.taskId != null);
const { dashboards } = useDashboards(params.channelId);
- const { dashboard: activeRecord } = useDashboard(params.dashboardId);
+ const { dashboard: activeRecord } = useDashboard(routeCanvasId ?? undefined);
const { data: allTasks } = useTasks(undefined, { enabled: hasTaskTab });
// Keyed on the active SESSION, not the path param: on Activity the session
// comes from the route's search, and without this its title would wait on the
@@ -305,9 +311,9 @@ function BrowserTabStripImpl() {
if (activeTaskRecord?.id === sessionId) return activeTaskRecord.title;
return allTasks?.find((t) => t.id === sessionId)?.title ?? null;
}
- if (params.dashboardId) {
- if (activeRecord?.id === params.dashboardId) return activeRecord.name;
- return dashboards.find((d) => d.id === params.dashboardId)?.name ?? null;
+ if (routeCanvasId) {
+ if (activeRecord?.id === routeCanvasId) return activeRecord.name;
+ return dashboards.find((d) => d.id === routeCanvasId)?.name ?? null;
}
if (activeReportId) {
if (activeReportRecord?.id !== activeReportId) return null;
@@ -316,7 +322,7 @@ function BrowserTabStripImpl() {
return null;
}, [
activeSession.taskId,
- params.dashboardId,
+ routeCanvasId,
activeReportId,
activeTaskRecord,
allTasks,
@@ -392,7 +398,7 @@ function BrowserTabStripImpl() {
// decision is made on: it is all-null outside its vocabulary, so two
// unrelated routes look identical through it.
const identity: TabIdentity = {
- dashboardId: params.dashboardId ?? null,
+ dashboardId: routeCanvasId,
// `activeSession`, not `params`: Activity and a feed read a session into
// the pane from their route's SEARCH rather than a path param, so the tab
// would otherwise show "New tab" over an open session.
@@ -516,7 +522,7 @@ function BrowserTabStripImpl() {
locationIsCurrent,
settledTabId,
params.channelId,
- params.dashboardId,
+ routeCanvasId,
routeChannelSection,
routeAppView,
locationHref,
@@ -568,7 +574,7 @@ function BrowserTabStripImpl() {
const pinned = pinnedSet.has(t.id);
const isActive = t.id === (settledTabId ?? activeTabId);
const taskId = isActive ? (activeSession.taskId ?? null) : t.taskId;
- const dashId = isActive ? (params.dashboardId ?? null) : t.dashboardId;
+ const dashId = isActive ? routeCanvasId : t.dashboardId;
const channelId = isActive
? (params.channelId ?? activeSession.channelId ?? null)
: t.channelId;
@@ -704,7 +710,7 @@ function BrowserTabStripImpl() {
activeTabId,
settledTabId,
params.channelId,
- params.dashboardId,
+ routeCanvasId,
activeSession.taskId,
activeSession.channelId,
activeReportId,
diff --git a/products/desktop/packages/ui/src/features/browser-tabs/tabAppViews.test.tsx b/products/desktop/packages/ui/src/features/browser-tabs/tabAppViews.test.tsx
index 050ad9e2cf0a..69f57c7c47b4 100644
--- a/products/desktop/packages/ui/src/features/browser-tabs/tabAppViews.test.tsx
+++ b/products/desktop/packages/ui/src/features/browser-tabs/tabAppViews.test.tsx
@@ -26,6 +26,7 @@ describe("resolveTabAppViewDisplay", () => {
["report", null, "Report"],
["report", { title: " " }, "Report"],
["inbox", { title: "Ignored report title" }, "Self-driving"],
+ ["canvases", null, "Canvases"],
] as const)("labels a %s tab with %o as %s", (appView, report, label) =>
expect(resolveTabAppViewDisplay(appView, report).label).toBe(label),
);
diff --git a/products/desktop/packages/ui/src/features/browser-tabs/tabAppViews.tsx b/products/desktop/packages/ui/src/features/browser-tabs/tabAppViews.tsx
index 40e3b34fbc17..919d6cc28bae 100644
--- a/products/desktop/packages/ui/src/features/browser-tabs/tabAppViews.tsx
+++ b/products/desktop/packages/ui/src/features/browser-tabs/tabAppViews.tsx
@@ -1,6 +1,7 @@
import {
ArchiveIcon,
BellIcon,
+ BlueprintIcon,
BookOpenTextIcon,
BrainIcon,
EnvelopeSimple,
@@ -18,6 +19,7 @@ import type { ReactNode } from "react";
export type TabAppView = Extract<
AppViewType,
| "activity"
+ | "canvases"
| "home"
| "inbox"
| "report"
@@ -39,6 +41,7 @@ export const TAB_APP_VIEW_META: Record<
label: "Activity",
icon: <BellIcon size={14} />,
},
+ canvases: { label: "Canvases", icon: <BlueprintIcon size={14} /> },
home: { label: "Home", icon: <SquaresFourIcon size={14} /> },
inbox: { label: "Self-driving", icon: <TrayIcon size={14} /> },
report: { label: "Report", icon: <FileTextIcon size={14} /> },
diff --git a/products/desktop/packages/ui/src/features/browser-tabs/useGoToTab.ts b/products/desktop/packages/ui/src/features/browser-tabs/useGoToTab.ts
index 061994c7145f..6db5522efe16 100644
--- a/products/desktop/packages/ui/src/features/browser-tabs/useGoToTab.ts
+++ b/products/desktop/packages/ui/src/features/browser-tabs/useGoToTab.ts
@@ -54,6 +54,15 @@ export function useGoToTab(): (tab: TabRef) => void {
case "activity":
navigate({ to: "/activity", state });
break;
+ case "canvases":
+ // The open canvas rides in the search, so a canvases tab that has
+ // no stored href still comes back on the canvas it showed.
+ navigate({
+ to: "/canvases",
+ search: { canvas: tab.dashboardId ?? undefined },
+ state,
+ });
+ break;
case "home":
case "report":
navigate({ to: "/", state });
diff --git a/products/desktop/packages/ui/src/router/useAppView.test.ts b/products/desktop/packages/ui/src/router/useAppView.test.ts
index 83d5e6130523..1560699f2e39 100644
--- a/products/desktop/packages/ui/src/router/useAppView.test.ts
+++ b/products/desktop/packages/ui/src/router/useAppView.test.ts
@@ -21,6 +21,13 @@ describe("getAppViewSnapshot", () => {
];
expect(getAppViewSnapshot()).toEqual({ type: "report" });
});
+ // A route missing from the switch falls through to the task-input view, which
+ // is outside the browser tab's label vocabulary. The tab then keeps the label
+ // of the page you came from.
+ it("gives the canvases page its own view", () => {
+ mocks.matches = [{ fullPath: "/canvases", params: {} }];
+ expect(getAppViewSnapshot()).toEqual({ type: "canvases" });
+ });
it.each([
{ fullPath: "/settings/$category", params: { category: "general" } },
{ fullPath: "/settings/", params: {} },
diff --git a/products/desktop/packages/ui/src/router/useAppView.ts b/products/desktop/packages/ui/src/router/useAppView.ts
index 98516485d55e..2fffbf63c5e3 100644
--- a/products/desktop/packages/ui/src/router/useAppView.ts
+++ b/products/desktop/packages/ui/src/router/useAppView.ts
@@ -16,6 +16,7 @@ export type AppViewType =
| "task-input"
| "folder-settings"
| "activity"
+ | "canvases"
| "home"
| "inbox"
| "report"
@@ -70,6 +71,8 @@ function deriveFromMatches(matches: Match[]): AppView {
return { type: "folder-settings", folderId: last.params.folderId };
case "/activity":
return { type: "activity" };
+ case "/canvases":
+ return { type: "canvases" };
case "/":
return { type: "home" };
case "/inbox":