Skip to content

Commit 615d95d

Browse files
authored
fix(canvas): wait for shortcuts before tracking space-viewed counts
CHANNELS_SPACE_VIEWED is a one-shot event gated only on the channels query. The stars/hides shortcuts query is independent, so if channels resolved first the event recorded starred_count and hidden_count as zero and viewedTrackedRef blocked any correction. Gate the effect on the shortcut queries' loading state too. Addresses Greptile P1. Generated-By: PostHog Code Task-Id: 4c16844c-acc9-4124-909d-f07335710a91
1 parent b6f77aa commit 615d95d

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

packages/ui/src/features/canvas/components/ChannelsList.tsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,8 @@ function PersonalChannelRow() {
562562
// into a "Hidden" group at the bottom.
563563
export function ChannelsList() {
564564
const { channels: allChannels, isLoading } = useChannels();
565-
const { starredRefToShortcutId } = useChannelStars();
566-
const { hiddenRefToShortcutId } = useChannelHides();
565+
const { starredRefToShortcutId, isLoading: starsLoading } = useChannelStars();
566+
const { hiddenRefToShortcutId, isLoading: hidesLoading } = useChannelHides();
567567
const [modalOpen, setModalOpen] = useState(false);
568568
// The "Hidden" group is collapsed by default — hidden channels are ones the
569569
// user chose to get out of the way.
@@ -578,19 +578,29 @@ export function ChannelsList() {
578578
const starred = visible.filter((c) => starredRefToShortcutId.has(c.path));
579579
const others = visible.filter((c) => !starredRefToShortcutId.has(c.path));
580580

581-
// Fire CHANNELS_SPACE_VIEWED once per space mount, after channels first load
582-
// (so the counts are accurate). The sidebar stays mounted while navigating
583-
// between channels, so this naturally fires once per entry into the space.
581+
// Fire CHANNELS_SPACE_VIEWED once per space mount, after channels *and* the
582+
// shortcuts (stars/hides) first load — the shortcuts query is independent, so
583+
// gating only on channels would let the one-shot event record stale zero
584+
// starred/hidden counts. The sidebar stays mounted while navigating between
585+
// channels, so this naturally fires once per entry into the space.
584586
const viewedTrackedRef = useRef(false);
585587
useEffect(() => {
586-
if (isLoading || viewedTrackedRef.current) return;
588+
if (isLoading || starsLoading || hidesLoading || viewedTrackedRef.current)
589+
return;
587590
viewedTrackedRef.current = true;
588591
track(ANALYTICS_EVENTS.CHANNELS_SPACE_VIEWED, {
589592
channel_count: channels.length,
590593
starred_count: starred.length,
591594
hidden_count: hidden.length,
592595
});
593-
}, [isLoading, channels.length, starred.length, hidden.length]);
596+
}, [
597+
isLoading,
598+
starsLoading,
599+
hidesLoading,
600+
channels.length,
601+
starred.length,
602+
hidden.length,
603+
]);
594604

595605
return (
596606
// One shared provider groups every row tooltip so that once one shows,

0 commit comments

Comments
 (0)