Skip to content

fix: メモリリークを修正#70

Open
watany-dev wants to merge 2 commits into
mainfrom
claude/fix-memory-leak-WGS4n
Open

fix: メモリリークを修正#70
watany-dev wants to merge 2 commits into
mainfrom
claude/fix-memory-leak-WGS4n

Conversation

@watany-dev
Copy link
Copy Markdown
Owner

  • diffCacheRef に LRU エビクション(上限50エントリ)を追加し、無制限なキャッシュ増大を防止
  • ページネーショントークン履歴に上限(50件)を追加し、無制限な配列増大を防止
  • 詳細画面からの戻りで重いステート(diffTexts, differences, comments等)をクリア
  • バックグラウンドの approval/reaction 取得に stale-load ガードを追加し、
    ナビゲーション後の不要なステート更新を防止

https://claude.ai/code/session_01AqB9UbJgm39kENE15PkGVq

- diffCacheRef に LRU エビクション(上限50エントリ)を追加し、無制限なキャッシュ増大を防止
- ページネーショントークン履歴に上限(50件)を追加し、無制限な配列増大を防止
- 詳細画面からの戻りで重いステート(diffTexts, differences, comments等)をクリア
- バックグラウンドの approval/reaction 取得に stale-load ガードを追加し、
  ナビゲーション後の不要なステート更新を防止

https://claude.ai/code/session_01AqB9UbJgm39kENE15PkGVq
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

PR詳細画面まわりで発生していたメモリリーク/不要なステート更新を抑止するため、キャッシュ・履歴・画面遷移時のステート管理を改善するPRです。

Changes:

  • diff表示キャッシュ(diffCacheRef)に上限50のLRUエビクションを追加
  • ページネーショントークン履歴を上限50に制限
  • 詳細画面から戻る際に重い詳細ステートをクリアし、バックグラウンドのapproval/reaction取得にstale-loadガードを追加

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/components/PullRequestDetail.tsx diff表示用キャッシュにLRU(最大50件)を導入して無制限増大を防止
src/app.tsx pagination履歴の上限設定、詳細画面離脱時の重いステートクリア、approval/reactionのstale-loadガード追加
src/app.test.tsx evaluateApprovalRules失敗時でもapproveフローが成立することの回帰テストを追加

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/app.tsx
Comment on lines +689 to 694
setApprovalEvaluation(null);
setReactionsByComment(new Map());
setCommits([]);
setCommitDifferences([]);
setCommitDiffTexts(new Map());
setScreen("prs");
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

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

Related to clearing commit/diff state on back: handleLoadCommitDiff() isn’t guarded/cancellable, so if the user presses back while a commit diff load is in-flight, the async completion can repopulate commits/commitDifferences/commitDiffTexts after these are cleared here. Please add a stale-load guard (e.g., reuse/increment diffLoadRef or a dedicated commitLoadRef) and bail out before setting these states when the detail screen has been exited.

Copilot uses AI. Check for mistakes.
Comment thread src/app.tsx
Comment on lines 680 to +686
function handleBack() {
if (screen === "detail") {
// Clear heavyweight detail state to free memory
setPrDetail(null);
setPrDifferences([]);
setCommentThreads([]);
setDiffTexts(new Map());
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

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

handleBack() clears the heavy detail state, but it doesn’t invalidate in-flight/background loads that are guarded by diffLoadRef. Since diffLoadRef.current remains equal to the last loadId, loadDiffTextsInBackground() (and the guarded approvals/reactions) can still update state after navigating back, which can repopulate diffTexts/diffTextStatus etc. Consider incrementing diffLoadRef.current (or setting it to a new token) at the start of the screen === "detail" back path to cancel any ongoing detail loads before clearing state.

Copilot uses AI. Check for mistakes.
- handleBack で diffLoadRef をインクリメントし、進行中のバックグラウンドロードを無効化
- handleLoadCommitDiff に stale-load ガードを追加し、ナビゲーション後の不要なステート更新を防止

https://claude.ai/code/session_01AqB9UbJgm39kENE15PkGVq
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.

3 participants