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): stop feed cards querying git while off screen (#99770)

Charles Vien64b139ce7272
diff --git a/products/desktop/packages/ui/src/features/canvas/components/ChannelFeedView.test.tsx b/products/desktop/packages/ui/src/features/canvas/components/ChannelFeedView.test.tsx
index 172684f5b619..0a8514acf037 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/ChannelFeedView.test.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/components/ChannelFeedView.test.tsx
@@ -123,9 +123,11 @@ afterEach(() => {
});
// ExpandablePrompt measures how the prompt wraps to decide where to cut and
-// whether to show "more". jsdom does no layout, so simulate a 21px line height
-// and a scrollHeight that grows with text length (≈20 chars/line).
+// whether to show "more". jsdom does no layout, so simulate a 21px line height,
+// a scrollHeight that grows with text length (≈20 chars/line), and a non-zero
+// width — the prompt skips measuring an element that has no width yet.
function mockLayout(charsPerLine: number) {
+ vi.spyOn(HTMLElement.prototype, "clientWidth", "get").mockReturnValue(600);
const realGetComputedStyle = window.getComputedStyle;
vi.spyOn(window, "getComputedStyle").mockImplementation((el, ...rest) => {
const style = realGetComputedStyle(el, ...rest);
diff --git a/products/desktop/packages/ui/src/features/canvas/components/ChannelFeedView.tsx b/products/desktop/packages/ui/src/features/canvas/components/ChannelFeedView.tsx
index 0bbf985523c1..9b7d4ceb9743 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/ChannelFeedView.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/components/ChannelFeedView.tsx
@@ -16,6 +16,7 @@ import { buildThreadTimeline } from "@posthog/core/canvas/threadTimeline";
import type { PrCheck } from "@posthog/core/git/router-schemas";
import { parsePrNumber } from "@posthog/core/git-interaction/prStatus";
import { xmlToPlainText } from "@posthog/core/message-editor/content";
+import type { TaskData } from "@posthog/core/sidebar/sidebarData.types";
import { isTaskActivelyRunning } from "@posthog/core/sidebar/taskRunning";
import {
AvatarGroup,
@@ -152,10 +153,18 @@ interface TaskStatusDisplay {
// shipped task never reads "Ready + Merged" or a stale "In progress + PR
// ready". A failed/cancelled run suppresses the PR badge instead — that is a
// deliberate end state we should not soften with a PR.
-function useTaskStatusDisplay(task: Task): TaskStatusDisplay {
- const data = useChannelTaskData(task);
+function useTaskStatusDisplay(
+ task: Task,
+ // Derived by the caller: `useChannelTaskData` mounts queries, mutations and
+ // store subscriptions, so a card that already holds the data must not mount
+ // a second copy of that graph here.
+ data: TaskData | undefined,
+ options?: {
+ resolvePrStatus?: boolean;
+ },
+): TaskStatusDisplay {
const { prState } = useTaskPrStatus({
- id: task.id,
+ id: options?.resolvePrStatus === false ? "" : task.id,
cloudPrUrl: data?.cloudPrUrl ?? null,
taskRunEnvironment: data?.taskRunEnvironment ?? null,
});
@@ -258,7 +267,7 @@ export function TaskSummaryRow({
task: Task;
channelId: string;
}) {
- const statusDisplay = useTaskStatusDisplay(task);
+ const statusDisplay = useTaskStatusDisplay(task, useChannelTaskData(task));
return (
<Link
{...taskCardNavigation(channelId, task.id)}
@@ -299,7 +308,7 @@ export function TaskCard({
inThread?: boolean;
onOpen?: () => void;
}) {
- const statusDisplay = useTaskStatusDisplay(task);
+ const statusDisplay = useTaskStatusDisplay(task, useChannelTaskData(task));
const prUrl =
typeof task.latest_run?.output?.pr_url === "string"
? task.latest_run.output.pr_url
@@ -397,7 +406,13 @@ export function ExpandablePrompt({
useEffect(() => {
if (!measure || expanded) return;
+ let measuredWidth: number | null = null;
+ let frame: number | null = null;
const compute = () => {
+ frame = null;
+ const width = measure.clientWidth;
+ if (width === 0 || width === measuredWidth) return;
+ measuredWidth = width;
const lineHeight = parseFloat(getComputedStyle(measure).lineHeight);
const maxHeight = lineHeight * lines;
if (measure.scrollHeight <= maxHeight + 0.5) {
@@ -440,9 +455,14 @@ export function ExpandablePrompt({
};
compute();
- const observer = new ResizeObserver(compute);
+ const observer = new ResizeObserver(() => {
+ if (frame === null) frame = requestAnimationFrame(compute);
+ });
observer.observe(measure);
- return () => observer.disconnect();
+ return () => {
+ observer.disconnect();
+ if (frame !== null) cancelAnimationFrame(frame);
+ };
}, [children, expanded, lines, measure]);
const truncated = cut !== null;
@@ -741,8 +761,10 @@ const FeedItem = memo(function FeedItem({
onOpenThread: (task: Task, tab?: ThreadPanelTab) => void;
}) {
const { mutate: markTasksRead } = useMarkTaskActivityRead();
- const statusDisplay = useTaskStatusDisplay(task);
const taskData = useChannelTaskData(task);
+ const statusDisplay = useTaskStatusDisplay(task, taskData, {
+ resolvePrStatus: inView,
+ });
const { togglePin } = usePinnedTasks();
const { archiveTask } = useArchiveTask();
const { renameTask } = useRenameTask();