Skip to content

fix(docs-panel): throttle docs refresh (gemini PR #302 review)#303

Merged
hang-in merged 1 commit into
mainfrom
fix/docs-panel-refresh-throttle
May 29, 2026
Merged

fix(docs-panel): throttle docs refresh (gemini PR #302 review)#303
hang-in merged 1 commit into
mainfrom
fix/docs-panel-refresh-throttle

Conversation

@hang-in
Copy link
Copy Markdown
Owner

@hang-in hang-in commented May 29, 2026

Gemini PR #302 review follow-up (medium)

DocsSection.tsx 의 window focus + visibilitychange 리스너가 탭 복귀 시 거의 동시 발생 → bump (refreshTick 증가) 2회 호출 → scanDocs / loadPlanMeta 중복 IPC + 리렌더.

변경

  • useEffect(() => { ... }, []) (1b 블록, line ~138) 안에 closure 변수 lastBumpTime 추가
  • bump() 가 마지막 호출 이후 1초 이내면 setRefreshTick 호출을 무시 (Gemini 제안 throttle 값 그대로)
  • empty deps → 변수는 effect lifetime 동안 1회 생성, re-render 시 reset 안 됨
  • focus/visibilitychange 재로드 동작 + cleanup (removeEventListener) 그대로 보존
  • DocsSection 의 다른 로직 (필터 / DB join / scanDocs / loadPlanMeta / refreshTick deps) 무변경

Verification

  • tsc --noEmit: PASS (에러 0)
  • vitest run: 516 passed (50 files) — baseline 동일 (throttle 은 component effect 내부 closure 변경, 기존 테스트 영향 0)
  • throttle grep: lastBumpTime / > 1000 확인

회귀 가드

  • git diff --name-only: src/components/tunaflow/sidebar/DocsSection.tsx 1개 파일만
  • git diff src-tauri/: 0 lines (Rust 무변경 → cargo check 변경 0 충족)
  • DocsSection 외 src/ 변경: 0

Env 메모

  • worktree 격리 작업: node_modules 부재 → main repo symlink 사용 (.gitignore 처리됨, commit 영향 0). main repo tracked 파일 변경 0.

🤖 Generated with Claude Code

…#302)

탭 복귀 시 window focus + visibilitychange 가 거의 동시 발생해 bump (refreshTick 증가)
가 2회 호출되어 scanDocs/loadPlanMeta IPC 가 중복 실행되던 문제 수정.

effect closure 변수 lastBumpTime 으로 마지막 bump 시각을 기록해 1초 이내 중복
호출을 무시한다. empty deps 이므로 변수는 effect lifetime 동안 1회만 생성되고
re-render 시 reset 되지 않는다. focus/visibilitychange 재로드 동작과 cleanup 은
그대로 보존.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@hang-in hang-in merged commit 3faa8c4 into main May 29, 2026
2 checks passed
@hang-in hang-in deleted the fix/docs-panel-refresh-throttle branch May 29, 2026 10:18
Copy link
Copy Markdown

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

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 introduces a 1-second throttle to the bump function inside useEffect in DocsSection.tsx to prevent duplicate IPC calls when window focus and visibilitychange events occur almost simultaneously. The reviewer suggested initializing lastBumpTime to -Infinity instead of 0 to ensure the first call is always executed, preventing potential issues in test environments or if refactored to use performance.now().

Comment on lines +142 to +149
let lastBumpTime = 0;
const bump = () => {
const now = Date.now();
if (now - lastBumpTime > 1000) {
lastBumpTime = now;
setRefreshTick((n) => n + 1);
}
};
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

lastBumpTime0으로 초기화하면 일반적인 프로덕션 환경에서는 Date.now()가 매우 큰 값이므로 문제가 없지만, 다음과 같은 잠재적인 문제가 발생할 수 있습니다:

  1. 테스트 환경에서의 오작동: 단위 테스트(예: Vitest/Jest)에서 fake timers를 사용하거나 Date.now()0 또는 매우 작은 값으로 모킹하는 경우, 첫 번째 bump() 호출이 now - lastBumpTime > 1000 조건(예: 0 - 0 > 1000)을 만족하지 못해 무시될 수 있습니다.
  2. performance.now()로의 변경 가능성: 향후 시간 측정의 정밀도나 모노토닉 시간 측정을 위해 performance.now()로 변경할 경우, 페이지 로드 후 1초 이내에 발생하는 첫 번째 이벤트가 무시됩니다.

lastBumpTime-Infinity로 초기화하면 첫 번째 호출이 항상 즉시 실행되도록 보장할 수 있어 더 안전하고 견고합니다.

Suggested change
let lastBumpTime = 0;
const bump = () => {
const now = Date.now();
if (now - lastBumpTime > 1000) {
lastBumpTime = now;
setRefreshTick((n) => n + 1);
}
};
let lastBumpTime = -Infinity;
const bump = () => {
const now = Date.now();
if (now - lastBumpTime > 1000) {
lastBumpTime = now;
setRefreshTick((n) => n + 1);
}
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant