fix(docs-panel): throttle docs refresh (gemini PR #302 review)#303
Merged
Conversation
…#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>
There was a problem hiding this comment.
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); | ||
| } | ||
| }; |
There was a problem hiding this comment.
lastBumpTime을 0으로 초기화하면 일반적인 프로덕션 환경에서는 Date.now()가 매우 큰 값이므로 문제가 없지만, 다음과 같은 잠재적인 문제가 발생할 수 있습니다:
- 테스트 환경에서의 오작동: 단위 테스트(예: Vitest/Jest)에서 fake timers를 사용하거나
Date.now()를0또는 매우 작은 값으로 모킹하는 경우, 첫 번째bump()호출이now - lastBumpTime > 1000조건(예:0 - 0 > 1000)을 만족하지 못해 무시될 수 있습니다. 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); | |
| } | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Gemini PR #302 review follow-up (medium)
DocsSection.tsx의 windowfocus+visibilitychange리스너가 탭 복귀 시 거의 동시 발생 →bump(refreshTick 증가) 2회 호출 →scanDocs/loadPlanMeta중복 IPC + 리렌더.변경
useEffect(() => { ... }, [])(1b 블록, line ~138) 안에 closure 변수lastBumpTime추가bump()가 마지막 호출 이후 1초 이내면setRefreshTick호출을 무시 (Gemini 제안 throttle 값 그대로)removeEventListener) 그대로 보존Verification
tsc --noEmit: PASS (에러 0)vitest run: 516 passed (50 files) — baseline 동일 (throttle 은 component effect 내부 closure 변경, 기존 테스트 영향 0)lastBumpTime/> 1000확인회귀 가드
git diff --name-only:src/components/tunaflow/sidebar/DocsSection.tsx1개 파일만git diff src-tauri/: 0 lines (Rust 무변경 → cargo check 변경 0 충족)src/변경: 0Env 메모
node_modules부재 → main repo symlink 사용 (.gitignore처리됨, commit 영향 0). main repo tracked 파일 변경 0.🤖 Generated with Claude Code