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): clear unread space highlights (#83002)

Shy Alterf1c3adbf78f9
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.tsx
index c9fa34042180..a0cb7440f3ca 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,
+ markChannelSeen: vi.fn(),
}));
vi.mock("@posthog/ui/shell/analytics", () => ({
@@ -35,6 +36,10 @@ vi.mock("@posthog/ui/features/canvas/hooks/useChannels", () => ({
isLoading: mocks.channelsLoading,
}),
}));
+vi.mock("@posthog/ui/features/canvas/hooks/useMarkChannelSeen", () => ({
+ useMarkChannelSeen: (channelId: string | undefined) =>
+ mocks.markChannelSeen(channelId),
+}));
vi.mock("@posthog/ui/features/archive/useArchivedTaskIds", () => ({
useArchivedTaskIds: () => mocks.archivedTaskIds,
}));
@@ -123,7 +128,13 @@ describe("ChannelsSidebar", () => {
mocks.routeChannelId = undefined;
useCurrentChannelStore.setState({ currentChannelId: null });
useChannelPaneStore.setState({ pane: "channel" });
- useSidebarStore.setState({ channelsEnabled: false, open: true });
+ // hasUserSetOpen pins `open`, so the auto-open effect (which sees no
+ // workspaces in this harness) can't collapse it out from under the tests.
+ useSidebarStore.setState({
+ channelsEnabled: false,
+ open: true,
+ hasUserSetOpen: true,
+ });
});
// The sidebar is a two-pane slider: the channel list, and the channel you're
@@ -157,6 +168,25 @@ describe("ChannelsSidebar", () => {
expect(useCurrentChannelStore.getState().currentChannelId).toBe(ENG.id);
});
+ it("marks a channel seen only while its pane is visible", () => {
+ mocks.routeChannelId = ENG.id;
+ renderSidebar();
+ expect(mocks.markChannelSeen).toHaveBeenLastCalledWith(ENG.id);
+
+ act(() => showChannelList());
+
+ expect(mocks.markChannelSeen).toHaveBeenLastCalledWith(undefined);
+ });
+
+ // ⌘B collapses the sidebar to zero width but keeps the pane mounted. A poll
+ // landing behind it must not stamp the channel seen — nobody saw the pane.
+ it("does not mark a channel seen while the sidebar is closed", () => {
+ mocks.routeChannelId = ENG.id;
+ useSidebarStore.setState({ open: false });
+ renderSidebar();
+ expect(mocks.markChannelSeen).toHaveBeenLastCalledWith(undefined);
+ });
+
// Opening a channel from anywhere — a deep link, a mention, ⌘1-9 — has to
// land on the channel even if the list was left open.
it("follows the route back into a channel", () => {
diff --git a/products/desktop/packages/ui/src/features/canvas/components/ChannelsSidebar.tsx b/products/desktop/packages/ui/src/features/canvas/components/ChannelsSidebar.tsx
index cb0de025f396..bde9ebf63941 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/ChannelsSidebar.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/components/ChannelsSidebar.tsx
@@ -11,6 +11,7 @@ import { useChannelsSidebarStore } from "@posthog/ui/features/canvas/components/
import { useChannelPaneSwipe } from "@posthog/ui/features/canvas/hooks/useChannelPaneSwipe";
import { useChannelsLayout } from "@posthog/ui/features/canvas/hooks/useChannelsLayout";
import { useCurrentChannel } from "@posthog/ui/features/canvas/hooks/useCurrentChannel";
+import { useMarkChannelSeen } from "@posthog/ui/features/canvas/hooks/useMarkChannelSeen";
import { useTrackChannelsSpaceViewed } from "@posthog/ui/features/canvas/hooks/useTrackChannelsSpaceViewed";
import {
consumeKeepListForNextRoute,
@@ -57,10 +58,19 @@ import { useDeferredValue, useEffect, useRef } from "react";
function ChannelPanes({
channelId,
showList,
+ sidebarVisible,
}: {
channelId: string | null;
showList: boolean;
+ sidebarVisible: boolean;
}) {
+ // Mark the channel seen only while a reader can see its pane: this pane is
+ // the one showing (not the list) and the sidebar is on screen. A collapsed
+ // sidebar keeps both panes mounted, so without the visibility gate a mention
+ // landing behind it would clear the unread emphasis nobody saw.
+ const visibleChannelId =
+ !showList && sidebarVisible ? (channelId ?? undefined) : undefined;
+ useMarkChannelSeen(visibleChannelId);
const panesRef = useRef<HTMLDivElement | null>(null);
useChannelPaneSwipe(panesRef, {
// With no channel to slide to, the list is all there is — leave the gesture
@@ -246,7 +256,11 @@ export function ChannelsSidebar() {
<ProjectSwitcher />
</div>
<ChannelNav />
- <ChannelPanes channelId={currentChannelId} showList={showList} />
+ <ChannelPanes
+ channelId={currentChannelId}
+ showList={showList}
+ sidebarVisible={open || peek}
+ />
</>
) : bodyChannelsWorld ? (
<>
diff --git a/products/desktop/packages/ui/src/features/canvas/hooks/useMarkChannelSeen.ts b/products/desktop/packages/ui/src/features/canvas/hooks/useMarkChannelSeen.ts
index da75fe628136..b67da1bd1c4a 100644
--- a/products/desktop/packages/ui/src/features/canvas/hooks/useMarkChannelSeen.ts
+++ b/products/desktop/packages/ui/src/features/canvas/hooks/useMarkChannelSeen.ts
@@ -6,10 +6,9 @@ import { useEffect } from "react";
/**
* Looking at a channel reads it: stamp it seen so the sidebar drops its bold.
*
- * Called from ChannelHeader, which every channel surface renders — the feed,
- * Artifacts, Recents and CONTEXT.md all count as being in the channel, and
- * hanging this off the header means a new surface gets it for free rather than
- * having to remember.
+ * Main channel surfaces call this through ChannelHeader. The sidebar calls it
+ * separately while its channel pane is visible because opening that pane does
+ * not navigate the main window.
*
* Stamped with the newest activity rather than "now": a mention landing while
* you're looking re-stamps it, remounts don't churn the store, and the store