Repository navigation
ExpoKeepAwakeのActivity破棄後のdeactivate例外と2回目の有効化無視を解消 - #5979
Conversation
📝 Walkthrough概要新しい 変更内容useKeepAwakeフック実装と統合
シーケンス図sequenceDiagram
participant Component
participant useKeepAwake
participant expoKeepAwake as expo-keep-awake
participant AppState
Component->>useKeepAwake: mount
useKeepAwake->>expoKeepAwake: deactivateKeepAwake(tag)
note over expoKeepAwake: errors ignored
useKeepAwake->>expoKeepAwake: activateKeepAwakeAsync(tag)
useKeepAwake->>AppState: addEventListener('change')
AppState->>useKeepAwake: 'active' state change
useKeepAwake->>expoKeepAwake: deactivateKeepAwake(tag)
useKeepAwake->>expoKeepAwake: activateKeepAwakeAsync(tag)
Component->>useKeepAwake: unmount
useKeepAwake->>AppState: removeEventListener()
useKeepAwake->>expoKeepAwake: deactivateKeepAwake(tag)
推定コードレビュー工数🎯 3 (中程度) | ⏱️ ~25 分 詩
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/hooks/useKeepAwake.test.tsx (1)
29-31: ⚡ Quick win
jest.clearAllMocks()をafterEachに移してください。Line 29-31 は現状
beforeEachですが、このリポジトリのテスト規約に合わせてafterEachへ統一してください。🔧 提案差分
describe('useKeepAwake', () => { - beforeEach(() => { + afterEach(() => { jest.clearAllMocks(); });As per coding guidelines "Call
jest.clearAllMocks()inafterEachblocks".🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/hooks/useKeepAwake.test.tsx` around lines 29 - 31, The test setup currently calls jest.clearAllMocks() inside the beforeEach block; move that call into an afterEach block instead to conform to the repository test guideline. Locate the beforeEach in useKeepAwake.test.tsx, remove jest.clearAllMocks() from that beforeEach, and add an afterEach(() => { jest.clearAllMocks(); }) so mocks are cleared after each test case.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/hooks/useKeepAwake.test.tsx`:
- Around line 29-31: The test setup currently calls jest.clearAllMocks() inside
the beforeEach block; move that call into an afterEach block instead to conform
to the repository test guideline. Locate the beforeEach in
useKeepAwake.test.tsx, remove jest.clearAllMocks() from that beforeEach, and add
an afterEach(() => { jest.clearAllMocks(); }) so mocks are cleared after each
test case.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 116d35be-56f5-42d4-b8e9-cbdc26434b15
📒 Files selected for processing (4)
src/hooks/index.tssrc/hooks/useKeepAwake.test.tsxsrc/hooks/useKeepAwake.tssrc/screens/Main.tsx
概要
Sentry に報告されていた
ExpoKeepAwake.deactivateのThe current activity is no longer available例外と、路線選択を繰り返すと画面スリープが防止されなくなる不具合(同じネイティブバグの 2 つの症状)を解消する。変更の種類
変更内容
expo-keep-awakeの Android ネイティブ実装ExpoKeepAwakeManager.deactivateはcurrentActivity取得時に例外が出ると tags Set からタグが除去されないまま中断する。その結果、useKeepAwakecleanup が unhandled rejection を投げて Sentry に報告されるactivateがif (!isActivated)で短絡し、新しい Activity の window にFLAG_KEEP_SCREEN_ONが再付与されず画面がスリープしてしまうという同根の不具合が発生していた。前回の
suppressDeactivateWarnings指定は (1) を黙らせるだけで (2) の状態破損は残ったままだったため、Main 画面のuseKeepAwakeを自前ラッパーに置き換える。src/hooks/useKeepAwake.tsを新規追加。固定タグTrainLCDMainKeepAwakeを使い、マウント時とAppStateのactive復帰時にdeactivateKeepAwake → activateKeepAwakeAsyncを順に呼んでネイティブ側 tags Set を強制的にクリアし、新しい window にフラグを付け直す。cleanup 時の deactivate 例外も.catch(() => {})で握りつぶす。src/screens/Main.tsx:expo-keep-awakeのuseKeepAwake直接呼び出しを~/hooksの自前useKeepAwakeに置き換え(suppressDeactivateWarnings指定は自前フックに内包されたので除去)。src/hooks/index.ts: 自前フックの再エクスポートを追加。src/hooks/useKeepAwake.test.tsx: マウント時の deactivate→activate の順序、AppStateactive 復帰時の再実行、background 時の非実行、unmount 時のリスナー解除と deactivate、deactivate 失敗時の例外握りつぶしを検証。テスト
npm run lintが通ることnpm testが通ること(新規 5 ケース含む全 1546 ケース成功)npm run typecheckが通ること関連Issue
スクリーンショット(任意)
Generated by Claude Code
Summary by CodeRabbit
リリースノート
新機能
テスト
リファクタリング