refactor: extract UI timeout magic numbers into src/panel/constants.ts#62
Conversation
There was a problem hiding this comment.
Code Review
This pull request centralizes various hardcoded timeout values across multiple panel tabs into a new constants.ts file to improve maintainability. The feedback suggests addressing potential race conditions in TimelineTab.tsx when rapidly triggering correlation events by properly tracking and clearing the pending timeout ID.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| @@ -1,5 +1,6 @@ | |||
| import { useState, useMemo, useCallback, useRef, useEffect } from 'react'; | |||
| import type { TimelineEvent, TimelineEventType, RenderEventPayload, StateChangeEventPayload, EffectEventPayload, ErrorEventPayload, MemoryEventPayload, CorrelationResult, ContextChangeEventPayload } from '@/types'; | |||
| import { CORRELATION_FEEDBACK_MS, SNAPSHOT_CREATE_FEEDBACK_MS } from '../constants'; | |||
There was a problem hiding this comment.
To prevent race conditions when rapidly clicking different events to correlate, we should track and clear the pending timeout. We can declare a module-level variable to hold the timeout ID.
import { CORRELATION_FEEDBACK_MS, SNAPSHOT_CREATE_FEEDBACK_MS } from '../constants';
let correlationTimeoutId: ReturnType<typeof setTimeout> | null = null;
| setIsCorrelating(false); | ||
| } | ||
| ); | ||
| setTimeout(() => setIsCorrelating(false), 3000); | ||
| setTimeout(() => setIsCorrelating(false), CORRELATION_FEEDBACK_MS); |
There was a problem hiding this comment.
Clear any existing correlation timeout before starting a new one, and also clear it when the response successfully arrives. This prevents older timeouts from prematurely setting isCorrelating to false when multiple events are clicked in rapid succession.
| setIsCorrelating(false); | |
| } | |
| ); | |
| setTimeout(() => setIsCorrelating(false), 3000); | |
| setTimeout(() => setIsCorrelating(false), CORRELATION_FEEDBACK_MS); | |
| setIsCorrelating(false); | |
| if (correlationTimeoutId) { | |
| clearTimeout(correlationTimeoutId); | |
| correlationTimeoutId = null; | |
| } | |
| } | |
| ); | |
| if (correlationTimeoutId) { | |
| clearTimeout(correlationTimeoutId); | |
| } | |
| correlationTimeoutId = setTimeout(() => { | |
| setIsCorrelating(false); | |
| correlationTimeoutId = null; | |
| }, CORRELATION_FEEDBACK_MS); |
|
Hey @Kunall7890 — third PR in 24 hours, you're on a roll! 🎉 Same false-negative on the Star Check (read-replica lag, your star is there). I've applied the Refactor review — exactly the kind of PR I love ✅
One micro-nit (no change required)The JSDoc says "6 named timeout constants" but the file shows 22 lines of new code. I'd estimate that's 6 constants × ~3 lines each (declaration + JSDoc). If you have time, a 1-line comment at the top of the file listing all 6 constant names would be a nice "table of contents" for future contributors. But this is a 1% thing — the file is already great. Why this matters
Going to merge once CI re-runs. Issue #31 will auto-close. PR #64 from you is also in the queue — I'll get to it after this lands. — Hoài |
Linked issue
Closes #31
Type of change
What changed
Created src/panel/constants.ts with 6 named timeout constants and JSDoc.
Replaced all 8 setTimeout magic number literals across Panel.tsx,
TimelineTab.tsx, PerformanceTab.tsx, MemoryTab.tsx, and ReduxTab.tsx.
Zero behavior change — only names changed, values are identical.
Testing notes
$ npm run build
(build succeeds with no errors)
$ grep -rn "setTimeout" src/panel --include="*.tsx"
(all results show named constants, no raw numbers)
Checklist