Skip to content
This repository was archived by the owner on Aug 6, 2026. It is now read-only.

Commit b1892f8

Browse files
authored
fix(canvas): derive build elapsed time during render instead of via effect
react-doctor blocked CI with a `no-adjust-state-on-prop-change` error at CanvasBuildStatus.tsx: the effect called `setNow(Date.now())` to restart the clock when a new build became active, so the first commit after a build change briefly rendered the previous build's elapsed time. The `now` state was only ever read to compute the label, so drop it: the interval now just bumps a tick to force a re-render and the label is computed from `Date.now()` during render. This removes the duplicated state (one of the two remedies react-doctor suggests) rather than adding a `prev`-prop comparison, and it also means the label can never be stale. react-doctor and `biome ci` are clean; @posthog/ui typecheck plus the @posthog/ui (2323) and @posthog/core (2595) unit suites pass. Generated-By: PostHog Code Task-Id: 4928140a-2ab8-4fb3-86c1-e02d25f60cca
1 parent 34f02cf commit b1892f8

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

packages/ui/src/features/canvas/freeform/CanvasBuildStatus.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,23 @@ export function CanvasBuildStatus({
7070
);
7171
const activeId = active?.id;
7272

73-
// Elapsed-time ticker for the active build. Keyed on the build id so a new
74-
// build restarts the clock; idle when no build is active.
75-
const [now, setNow] = useState(() => Date.now());
73+
// Elapsed-time ticker for the active build: the interval only forces a
74+
// re-render, the label is derived from the clock during render. Keyed on the
75+
// build id so a new build restarts the ticker; idle when no build is active.
76+
const [, setTick] = useState(0);
7677
useEffect(() => {
7778
if (!activeId) return;
78-
setNow(Date.now());
79-
const timer = setInterval(() => setNow(Date.now()), ELAPSED_TICK_MS);
79+
const timer = setInterval(
80+
() => setTick((tick) => tick + 1),
81+
ELAPSED_TICK_MS,
82+
);
8083
return () => clearInterval(timer);
8184
}, [activeId]);
8285

8386
if (!lifecycle || lifecycle.builds.length === 0) return null;
8487

8588
if (active) {
86-
const elapsed = formatElapsed(now - Date.parse(active.createdAt));
89+
const elapsed = formatElapsed(Date.now() - Date.parse(active.createdAt));
8790
return (
8891
<Flex align="center" gap="1" data-testid="canvas-build-active">
8992
<SpinnerGapIcon size={14} className="animate-spin text-gray-9" />

0 commit comments

Comments
 (0)