Skip to content

位置情報関係のバグを修正 - #5273

Merged
TinyKitten merged 5 commits into
devfrom
fix/location-issues
Feb 13, 2026
Merged

TinyKitten merged 5 commits into
devfrom
fix/location-issues

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Feb 13, 2026 •

Copy link
Copy Markdown
Member

Summary by CodeRabbit

リリースノート

  • バグ修正
    • 駅検索モーダルを初めて開いた際に位置情報を自動で再取得するようにしました(表示中はモーダル専用の座標を使用)。
    • モーダル非表示時に一時的な座標をクリアするよう改善しました。
    • 初回の近隣駅取得処理を堅牢化し、重複実行の防止・タイムアウト的フォールバック・エラー処理を追加しました。
  • 改善
    • 外部から座標が提供された場合は即時に検索を実行する流れを追加しました。

@TinyKitten TinyKitten self-assigned this Feb 13, 2026
@github-actions github-actions Bot added the react label Feb 13, 2026
@coderabbitai

coderabbitai Bot commented Feb 13, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

StationSearchModalにモーダル専用のmodalCoords状態を追加し、モーダル初回表示時に現在地を再取得してmodalCoordsおよびグローバルの位置ストアへ反映。SelectLineScreenでは初期近隣駅取得を座標ベースで即時実行できるようにし、フォールバックタイマーと同時実行ガードを導入してエラーハンドリングを追加。

Changes

Cohort / File(s) Summary
StationSearchModal — ロケーション更新
src/components/StationSearchModal.tsx
モーダル表示中のみ使うローカルmodalCoordsを追加。モーダル初回表示時にuseFetchCurrentLocationOnceで現在地を取得してmodalCoordsとグローバルsetLocationへ反映。モーダル非表示でmodalCoordsをクリア。useRef/useState追加。
SelectLineScreen — 初期近隣フェッチの再構築
src/screens/SelectLineScreen.tsx
INITIAL_LOCATION_FALLBACK_DELAY_MS定数とinitialNearbyFetchInFlightRefを導入。fetchInitialNearbyStationAsyncが座標引数を受け取るようにし、propsのlatitude/longitudeがある場合は即時フェッチ、無ければフォールバックタイマーで遅延フェッチ。try/catch/finallyでエラーハンドリングとin-flightフラグのリセット、タイマー/クリーンアップ処理を追加。

Sequence Diagram(s)

sequenceDiagram
    participant User as User
    participant Modal as StationSearchModal
    participant Location as fetchCurrentLocation
    participant Store as Location Store
    User->>Modal: Open modal
    Note over Modal: modalVisible = true\n(first open)
    Modal->>Location: fetchCurrentLocation()
    Location-->>Modal: coords (lat,lng)
    Modal->>Modal: set modalCoords
    Modal->>Store: setLocation(coords)
    Store-->>Modal: ack
    User->>Modal: Close modal
    Note over Modal: clear modalCoords
Loading
sequenceDiagram
    participant Screen as SelectLineScreen
    participant Props as Route Props\n(latitude/longitude)
    participant Timer as Fallback Timer
    participant Fetch as fetchInitialNearbyStationAsync
    participant Result as Nearby Stations
    Screen->>Screen: check initialNearbyFetchInFlightRef
    alt coords provided via Props
        Props->>Fetch: invoke with coords
    else no coords
        Screen->>Timer: start INITIAL_LOCATION_FALLBACK_DELAY_MS
        Timer->>Fetch: invoke after delay
    end
    Fetch-->>Result: return stations / error
    Screen->>Screen: reset initialNearbyFetchInFlightRef
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

🐰 ひょいと跳んでモーダル開くと、
ちいさな座標がぴょこんと届くよ。
タイマーは待って、位置は更新、
駅を探す足音、ぴょんぴょん早く。
祝おう、コードとにんじんで乾杯! 🥕✨

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed プルリクエストのタイトルは「位置情報関係のバグを修正」で、変更内容は位置情報処理のリファクタリング(モーダル表示時の位置情報更新、初期位置情報フェッチロジックの改善)です。タイトルは変更内容に関連していますが、修正対象のバグの具体的な内容や対象コンポーネント(StationSearchModal、SelectLineScreen)が明記されていないため、抽象度が高く、より具体的な説明が望ましいです。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into dev

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/location-issues

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
src/components/StationSearchModal.tsx (1)

158-186: 位置情報取得の実装は適切です。エラーハンドリングについて軽微な確認。

activeフラグによるクリーンアップパターンとwasVisibleRefガードの実装は非同期処理に適しています。

Line 177-179のエラーハンドリングはconsole.errorのみですが、意図的な設計でしょうか?既存のfetchStationsNearbyError等のエラーハンドリング(Line 188-192)と同様にユーザーへのアラート表示が必要な場合は追加を検討してください。現状でも問題なく動作しますが、位置情報取得失敗時にユーザーに通知したい場合は以下のように修正できます。

🔧 オプション:エラー時にアラートを表示する場合
     const refreshLocation = async () => {
       try {
         const currentLocation = await fetchCurrentLocation();
         if (!active) return;
         setModalCoords({
           latitude: currentLocation.coords.latitude,
           longitude: currentLocation.coords.longitude,
         });
         setLocation(currentLocation);
       } catch (error) {
         console.error(error);
+        if (active) {
+          Alert.alert(translate('errorTitle'), translate('failedToFetchLocation'));
+        }
       }
     };

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/components/StationSearchModal.tsx (1)

120-177: ⚠️ Potential issue | 🟠 Major

モーダル非表示後の非同期操作による状態更新を抑止

fetchCurrentLocation() が非同期であり、モーダル閉鎖後に完了した場合、setModalCoords と setLocation が呼ばれて古い座標が再設定される競合状況が発生します。クリーンアップで active フラグを使用して、完了後の状態更新をガードしてください。

🔧 修正案
 useEffect(() => {
+  let active = true;
   if (!visible) {
     setModalCoords(null);
     wasVisibleRef.current = false;
-    return;
+    return () => {
+      active = false;
+    };
   }
   if (wasVisibleRef.current) return;
   wasVisibleRef.current = true;

   const refreshLocation = async () => {
     try {
       const currentLocation = await fetchCurrentLocation();
+      if (!active) return;
       setModalCoords({
         latitude: currentLocation.coords.latitude,
         longitude: currentLocation.coords.longitude,
       });
       setLocation(currentLocation);
     } catch (error) {
-      console.error(error);
+      if (active) {
+        console.error(error);
+      }
     }
   };

   refreshLocation();
+  return () => {
+    active = false;
+  };
 }, [visible, fetchCurrentLocation]);

@TinyKitten
TinyKitten merged commit baceca9 into dev Feb 13, 2026
5 checks passed
@TinyKitten
TinyKitten deleted the fix/location-issues branch February 13, 2026 14:10
@coderabbitai coderabbitai Bot mentioned this pull request Feb 25, 2026
5 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant