Repository navigation
watchPositionAsyncの直接コールバックを併用してAndroid 16のJobSchedulerクォータによるバックグラウンド位置更新のスロットルを回避 - #5427
Conversation
|
No actionable comments were generated in the recent review. 🎉 📝 WalkthroughWalkthrough
Changes
Sequence DiagramsequenceDiagram
participant App as App/Component
participant Hook as useStartBackgroundLocationUpdates
participant LocationAPI as Location API
participant Watch as watchPositionAsync
App->>Hook: マウント(bgPermGranted=true)
activate Hook
Hook->>LocationAPI: startLocationUpdatesAsync(...)
activate LocationAPI
LocationAPI-->>Hook: 成功
deactivate LocationAPI
alt NEEDS_JOBSCHEDULER_BYPASS == true
Hook->>Watch: watchPositionAsync(LOCATION_WATCH_OPTIONS, cb)
activate Watch
Watch-->>Hook: Subscription を返す
deactivate Watch
Watch->>App: リアルタイム位置更新を送信
end
App->>Hook: アンマウント/キャンセル
Hook->>Watch: remove()(watchPositionSub があれば)
Hook->>LocationAPI: stopLocationUpdatesAsync(...)
deactivate Hook
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/hooks/useStartBackgroundLocationUpdates.ts`:
- Line 34: watchPositionAsync is being passed LOCATION_TASK_OPTIONS (a
LocationTaskOptions) which includes task-only fields like
deferredUpdatesInterval that watchPositionAsync ignores; create a proper
Location.LocationOptions object (or derive one by picking only accuracy,
timeInterval, distanceInterval, mayShowUserSettingsDialog, etc.) from
LOCATION_TASK_OPTIONS and pass that to watchPositionAsync in the
useStartBackgroundLocationUpdates hook (update the two calls that currently pass
LOCATION_TASK_OPTIONS), ensuring the runtime type matches
Location.LocationOptions and removing task-only keys before invoking
watchPositionAsync.
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/hooks/useStartBackgroundLocationUpdates.test.tsx (1)
52-60:⚠️ Potential issue | 🟡 Minor
afterEachでのjest.clearAllMocks()が必要です。
ガイドラインに従い、afterEachにもクリアを追加してください(必要ならbeforeEachは維持でOK)。修正案
beforeEach(() => { // React Testing Libraryのauto-cleanupはafterEachでフックをunmountし、 // effectクリーンアップ(stopLocationUpdatesAsync等)を発火する。 // このクリーンアップは登録順の関係でafterEachよりも後に実行されるため、 // beforeEachでclearAllMocksを行い、前テストの残留呼び出しを確実にリセットする。 jest.clearAllMocks(); mockAutoModeEnabled = false; mockNeedsJobSchedulerBypass = false; mockStartLocationUpdatesAsync.mockResolvedValue(undefined); mockStopLocationUpdatesAsync.mockResolvedValue(undefined); mockHasStartedLocationUpdatesAsync.mockResolvedValue(false); mockWatchPositionAsync.mockResolvedValue({ remove: mockRemove }); }); + afterEach(() => { + jest.clearAllMocks(); + });As per coding guidelines, “Call
jest.clearAllMocks()inafterEachblocks in all test files”.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/hooks/useStartBackgroundLocationUpdates.test.tsx` around lines 52 - 60, Add a call to jest.clearAllMocks() in the test file's afterEach block to match the project guideline (you may keep the existing beforeEach clear). Specifically, update the test teardown (afterEach) so it invokes jest.clearAllMocks() before any other cleanup, ensuring mocks like mockStartLocationUpdatesAsync and flags (mockAutoModeEnabled, mockNeedsJobSchedulerBypass) are reset after each test; leave the existing beforeEach setup intact.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@src/hooks/useStartBackgroundLocationUpdates.test.tsx`:
- Around line 52-60: Add a call to jest.clearAllMocks() in the test file's
afterEach block to match the project guideline (you may keep the existing
beforeEach clear). Specifically, update the test teardown (afterEach) so it
invokes jest.clearAllMocks() before any other cleanup, ensuring mocks like
mockStartLocationUpdatesAsync and flags (mockAutoModeEnabled,
mockNeedsJobSchedulerBypass) are reset after each test; leave the existing
beforeEach setup intact.
https://claude.ai/code/session_01RMxd9GFPAFTnDB531mMTrP
Summary by CodeRabbit
テスト
改善
ログ