Skip to content

JR西日本テーマのTTS停車駅リストが初回以降案内されない不具合を修正 - #5692

Merged
TinyKitten merged 3 commits into
devfrom
feature/fix-jr-west-tts-batch-cycling
Mar 26, 2026
Merged

TinyKitten merged 3 commits into
devfrom
feature/fix-jr-west-tts-batch-cycling

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Mar 26, 2026 •

Copy link
Copy Markdown
Member

Summary

  • JR西日本テーマのTTSで「〜から先は後ほどご案内いたします」と案内しながら、実際にはその先の駅に到達しても案内が行われないバグを修正
  • 停車駅リスト(5駅分)の案内がfirstSpeech(初回放送)時のみに限定されていたのを、5駅ごとのサイクル境界で再案内されるように変更
  • 日本語・英語両テンプレートに適用

Changes

  • currentStopIndex: 進行方向上で現在何番目の停車駅にいるかを純粋に計算するuseMemoを追加
  • shouldAnnounceJrWestStopList: currentStopIndex % 5 === 0の境界でtrueを返すuseMemoを追加
  • JR_WEST NEXT テンプレートの停車駅リスト部分をfirstSpeech条件から分離し、shouldAnnounceJrWestStopListで制御

Test plan

  • npm run lint パス
  • npm test パス(既存28テスト + 新規3テスト = 31テスト全パス)
  • npm run typecheck パス
  • JR_WESTテーマのNEXT/ARRIVINGでundefinedが含まれないことを確認
  • 実機でJR西日本テーマを選択し、5駅以上の路線で停車駅リストが再案内されることを確認

🤖 Generated with Claude Code

Summary by CodeRabbit

リリースノート

  • バグ修正

    • JR西日本向けの車内放送(次の停車駅案内)の挙動を改善。初回案内と以降の案内で「次の5駅/後ほど案内」の表現が正しく切り替わるようにしました。
  • テスト

    • JR西日本の案内バッチ切替を検証する新しいテストを追加し、日本語・英語それぞれで期待される案内表現を確認しています。

@github-actions github-actions Bot added the react label Mar 26, 2026
@coderabbitai

coderabbitai Bot commented Mar 26, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

JR西日本向けの停車駅リスト案内を、現在停車位置と「最初の5停車駅」境界に基づき条件付きで生成するメモ化ロジックを追加し、その挙動を検証するテストスイートを導入しました。

Changes

Cohort / File(s) Summary
JR西日本ロジック変更
src/hooks/useTTSText.ts
JR_WEST用にcurrentStopIndex、shouldAnnounceJrWestStopList、lastAnnouncedStopを導入。日本語・英語のNEXTテンプレートで停車駅リスト出力を条件化し、境界判定や比較にgroupId/lastAnnouncedStopを使用。メモ化依存配列を更新。
テスト追加・拡張
src/hooks/useTTSText.test.tsx
JR_WEST向けのバッチサイクリング検証を追加。themePreferenceAtom設定、useNumberingモック、useCyclingHelperによるrerenderで、初回案内・同バッチ内での切替・バッチ境界超過後の再案内と英語/日本語出力を3件のアサーションで確認。

Sequence Diagram(s)

(該当なし)

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰🎶 線路ぴょんと跳ねて知らせる
五つの境目で声を変えるよ
はじめに言い、また後で告げる
テストで確かめてすっきりと
うさぎはぴょんと次を待つよ

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed PRタイトルは、JR西日本テーマのTTS停車駅リストが初回以降案内されない不具合を修正することを明確に説明しており、メインの変更内容と完全に関連している。
Description check ✅ Passed PR説明では、「概要」「変更内容」「テスト」セクションが充実して記述されており、テンプレートのほぼすべての必須項目がカバーされている。ただし「変更の種類」セクションにはチェックボックスの記入がなく、「関連Issue」のリンクも明示されていない。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fix-jr-west-tts-batch-cycling

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

@TinyKitten TinyKitten self-assigned this Mar 26, 2026

@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.

🧹 Nitpick comments (3)
src/hooks/useTTSText.ts (2)

562-568: 重複した計算の抽出を検討してください

allStops.slice(0, 5).filter(Boolean).reverse()[0] が .id、.name、.nameKatakana の各アクセスで繰り返し計算されています。可読性と軽微なパフォーマンス改善のため、変数への抽出を検討してください。

♻️ 提案する修正
+          const lastBatchStop = allStops.slice(0, 5).filter(Boolean).reverse()[0];
           ...
-                  allStops.slice(0, 5).filter(Boolean).reverse()[0]?.id ===
+                  lastBatchStop?.id ===
                   selectedBound?.id
                     ? ''
                     : `${replaceJapaneseText(
-                        allStops.slice(0, 5).filter(Boolean).reverse()[0]?.name,
-                        allStops.slice(0, 5).filter(Boolean).reverse()[0]
-                          ?.nameKatakana
+                        lastBatchStop?.name,
+                        lastBatchStop?.nameKatakana
                       )}から先は、後ほどご案内いたします。`
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/hooks/useTTSText.ts` around lines 562 - 568, The expression
allStops.slice(0, 5).filter(Boolean).reverse()[0] is computed repeatedly when
comparing ids and accessing .name/.nameKatakana; extract that value into a local
variable (e.g., lastStop) before the ternary so subsequent uses in the
conditional and in the call to replaceJapaneseText reuse the same reference,
then update the conditional to compare lastStop.id to selectedBound?.id and pass
lastStop.name and lastStop.nameKatakana to replaceJapaneseText to improve
readability and avoid redundant computation.

997-1004: 同様の重複計算(英語テンプレート)

日本語テンプレート(562-568行)と同様に、allStops.slice(0, 5).filter(Boolean).reverse()[0] が複数回計算されています。同じリファクタリングを適用できます。

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/hooks/useTTSText.ts` around lines 997 - 1004, The duplicated expression
allStops.slice(0, 5).filter(Boolean).reverse()[0] is computed multiple times in
the English template (and similarly in the Japanese template); introduce a local
constant (e.g., lastVisibleStop or lastStop) just above where the templates are
built, assign that expression once, and then replace all repeated occurrences in
the conditional and in the ph(...) calls (referencing lastVisibleStop?.id,
lastVisibleStop?.nameTtsSegments, lastVisibleStop?.nameRoman) as well as in the
Japanese template’s uses to avoid redundant work and improve readability.
src/hooks/useTTSText.test.tsx (1)

424-436: act() の使用箇所について

act() は React の状態更新をラップするためのものですが、ここでは単純な変数代入をラップしています。動作には問題ありませんが、より慣用的な書き方としては act() を省略できます。

♻️ 提案する修正
-    act(() => {
-      firstSpeech = false;
-    });
+    firstSpeech = false;
     rerender({});
     expect(result.current.text[0]).not.toContain('の順に停まります');

     // Phase 3: move to station 5 (神保町) → past batch boundary → re-announce
     // Station index 5 = 神保町, nextStation = 小川町 (index 6)
     setupMockUseNextStation(TOEI_SHINJUKU_LINE_STATIONS[6]);
-    act(() => {
-      stationIndex = 5;
-    });
+    stationIndex = 5;
     rerender({});
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/hooks/useTTSText.test.tsx` around lines 424 - 436, The test unnecessarily
wraps simple variable assignments in act(); remove the act() wrapper around
"firstSpeech = false" and "stationIndex = 5" and just perform the assignments
directly before calling rerender(), leaving setupMockUseNextStation(...) and
rerender({}) unchanged so the hook update flow (setupMockUseNextStation,
stationIndex change, then rerender) remains intact.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/hooks/useTTSText.test.tsx`:
- Around line 424-436: The test unnecessarily wraps simple variable assignments
in act(); remove the act() wrapper around "firstSpeech = false" and
"stationIndex = 5" and just perform the assignments directly before calling
rerender(), leaving setupMockUseNextStation(...) and rerender({}) unchanged so
the hook update flow (setupMockUseNextStation, stationIndex change, then
rerender) remains intact.

In `@src/hooks/useTTSText.ts`:
- Around line 562-568: The expression allStops.slice(0,
5).filter(Boolean).reverse()[0] is computed repeatedly when comparing ids and
accessing .name/.nameKatakana; extract that value into a local variable (e.g.,
lastStop) before the ternary so subsequent uses in the conditional and in the
call to replaceJapaneseText reuse the same reference, then update the
conditional to compare lastStop.id to selectedBound?.id and pass lastStop.name
and lastStop.nameKatakana to replaceJapaneseText to improve readability and
avoid redundant computation.
- Around line 997-1004: The duplicated expression allStops.slice(0,
5).filter(Boolean).reverse()[0] is computed multiple times in the English
template (and similarly in the Japanese template); introduce a local constant
(e.g., lastVisibleStop or lastStop) just above where the templates are built,
assign that expression once, and then replace all repeated occurrences in the
conditional and in the ph(...) calls (referencing lastVisibleStop?.id,
lastVisibleStop?.nameTtsSegments, lastVisibleStop?.nameRoman) as well as in the
Japanese template’s uses to avoid redundant work and improve readability.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 63672792-5be8-4260-83c1-8b8873f27104

📥 Commits

Reviewing files that changed from the base of the PR and between e72de39 and 570d023.

📒 Files selected for processing (2)
  • src/hooks/useTTSText.test.tsx
  • src/hooks/useTTSText.ts

@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.

Actionable comments posted: 2

🤖 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/useTTSText.ts`:
- Around line 559-573: The end-of-line check uses selectedBound?.id and
lastAnnouncedStop?.id which can mismatch for shared/through stations; change
those comparisons to use groupId instead (e.g., compare s.groupId /
lastAnnouncedStop?.groupId against selectedBound?.groupId) inside the
shouldAnnounceJrWestStopList block (around the allStops.slice(...).map(...) and
the trailing lastAnnouncedStop conditional) and apply the same replacement in
the other occurrence referenced (the similar logic at lines ~993-1007) so
end-of-line detection consistently uses groupId.
- Around line 265-277: currentStopIndex is computed from raw stations so its
indexing can diverge from the deduplicated/stop-filtered list used elsewhere;
update the currentStopIndex useMemo to derive its ordered stops from the same
deduplicated stop list (e.g. use allStops or the same groupId-deduped array used
at lines ~220-225), apply the same !getIsPass filter and direction-based
ordering, then call findIndex on that deduped array using station.groupId; also
update the dependency array to depend on that deduped list (e.g. allStops)
instead of raw stations so shouldAnnounceJrWestStopList and currentStopIndex
remain consistent.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2c48a06a-ce4e-43c5-b9df-73370b255060

📥 Commits

Reviewing files that changed from the base of the PR and between 570d023 and babc549.

📒 Files selected for processing (2)
  • src/hooks/useTTSText.test.tsx
  • src/hooks/useTTSText.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/hooks/useTTSText.test.tsx

Comment thread src/hooks/useTTSText.ts Resolved
Comment thread src/hooks/useTTSText.ts Resolved

@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.

🧹 Nitpick comments (1)
src/hooks/useTTSText.ts (1)

265-273: groupId の重複排除は共通化しておくと保守しやすいです。

Line 221-225 とここで同じ dedupe を別実装にしているので、次に片方だけ変わると allStops 側と currentStopIndex 側がまたずれやすいです。小さい helper に寄せて両方から使う形にしておくと安全です。

♻️ 例
+const dedupeStationsByGroupId = (stations: Station[]): Station[] => {
+  const seen = new Set<Station['groupId']>();
+  return stations.filter((s) => {
+    if (seen.has(s.groupId)) {
+      return false;
+    }
+    seen.add(s.groupId);
+    return true;
+  });
+};
+
   // 直通時、同じGroupIDの駅が違う駅として扱われるのを防ぐ(ex. 渋谷の次は渋谷に止まります)
-  const slicedStations = Array.from(
-    new Set(slicedStationsOrigin.map((s) => s.groupId))
-  )
-    .map((gid) => slicedStationsOrigin.find((s) => s.groupId === gid))
-    .filter((s) => !!s) as Station[];
+  const slicedStations = dedupeStationsByGroupId(slicedStationsOrigin);
…
-    const deduped = Array.from(new Set(ordered.map((s) => s.groupId)))
-      .map((gid) => ordered.find((s) => s.groupId === gid))
-      .filter((s) => !!s) as Station[];
+    const deduped = dedupeStationsByGroupId(ordered);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/hooks/useTTSText.ts` around lines 265 - 273, Extract the duplicated
"dedupe by groupId + preserve order + skip passes" logic into a small helper
(e.g., dedupeStationsByGroupId or buildAllStops) and replace the inline logic
inside currentStopIndex with a call to that helper; ensure the helper accepts
the stations array and selectedDirection (or an already-ordered array) and
returns the deduped stops array (used previously in allStops and here), then
compute currentStopIndex by finding the station.groupId in the helper's result
to keep both places consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/hooks/useTTSText.ts`:
- Around line 265-273: Extract the duplicated "dedupe by groupId + preserve
order + skip passes" logic into a small helper (e.g., dedupeStationsByGroupId or
buildAllStops) and replace the inline logic inside currentStopIndex with a call
to that helper; ensure the helper accepts the stations array and
selectedDirection (or an already-ordered array) and returns the deduped stops
array (used previously in allStops and here), then compute currentStopIndex by
finding the station.groupId in the helper's result to keep both places
consistent.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: af156b71-5077-45b2-ba58-0464981bda9d

📥 Commits

Reviewing files that changed from the base of the PR and between babc549 and 90292f4.

📒 Files selected for processing (1)
  • src/hooks/useTTSText.ts

@TinyKitten
TinyKitten merged commit 2b267a7 into dev Mar 26, 2026
5 checks passed
@TinyKitten
TinyKitten deleted the feature/fix-jr-west-tts-batch-cycling branch March 26, 2026 23:35
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