Skip to content

refactor: extract UI timeout magic numbers into src/panel/constants.ts#62

Merged
hoainho merged 1 commit into
hoainho:mainfrom
Kunall7890:refactor/extract-timeout-constants
Jun 7, 2026
Merged

refactor: extract UI timeout magic numbers into src/panel/constants.ts#62
hoainho merged 1 commit into
hoainho:mainfrom
Kunall7890:refactor/extract-timeout-constants

Conversation

@Kunall7890

Copy link
Copy Markdown
Contributor

Linked issue

Closes #31

Type of change

  • Refactor (no behavior 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

  • npm run build succeeds
  • No behavior change
  • PR title follows Conventional Commits
  • No new dependencies added

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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;

Comment on lines 90 to +93
setIsCorrelating(false);
}
);
setTimeout(() => setIsCorrelating(false), 3000);
setTimeout(() => setIsCorrelating(false), CORRELATION_FEEDBACK_MS);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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);

@hoainho hoainho added the pre-star-rule PR opened before the star-check rule landed (2026-06-01); exempt from Star Check CI label Jun 7, 2026
@hoainho

hoainho commented Jun 7, 2026

Copy link
Copy Markdown
Owner

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 pre-star-rule label to bypass and re-run. No action needed on your side.

Refactor review — exactly the kind of PR I love ✅

6 named constants in new src/panel/constants.ts ✅ Self-documenting names + JSDoc on each constant.
8 setTimeout call-sites updated ✅ All magic numbers replaced, zero behavior change.
6 files touched, 35+ / 8- ✅ Minimal, focused, no drive-by changes.
JSDoc ✅ "Values tuned for perceived responsiveness without flicker" — captures the why not just the what.
Closes #31 properly ✅ Auto-closes on merge.

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

  • From "magic numbers everywhere" → "named constants with intent" is a real readability + maintainability win. New contributors won't have to grep for 3000 to figure out what the debugger toggle feedback timer does.
  • This is the kind of refactor that's easy to undervalue — but in 6 months when someone wants to tune one of these, they'll thank you for the named constants.
  • Hits on launch day 🚀 — goes into the v2.0.3 changelog.

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

@hoainho hoainho merged commit dcc96fb into hoainho:main Jun 7, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pre-star-rule PR opened before the star-check rule landed (2026-06-01); exempt from Star Check CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor: extract UI timeout magic numbers into src/panel/constants.ts

2 participants