Skip to content

高頻度atom購読の隔離で位置更新ごとの全画面再レンダーを解消 - #6422

Merged
TinyKitten merged 6 commits into
devfrom
feature/style-cleanup-and-render-stability
Jul 16, 2026
Merged

TinyKitten merged 6 commits into
devfrom
feature/style-cleanup-and-render-stability

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Jul 15, 2026 •

Copy link
Copy Markdown
Member

概要

走行中の Main 画面が位置更新(毎秒)のたびに画面全体で再レンダーされていた問題を、実機プロファイルに基づいて解消しました。実機計測(moto g05・オートモード走行、dev ビルド)でレンダー時間合計 259→167ms/秒(−36%)、最大コミット時間 558→234ms(−58%)を確認しています。#6421(未使用スタイル削除・ListFooter/Toast 切り出し)の続きです。

変更の種類

  • バグ修正
  • 新機能
  • リファクタリング
  • ドキュメント
  • CI/CD
  • その他

変更内容

  • locationAtom など高頻度更新 atom を購読する返り値なしの副作用フックを、MainScreen / PermittedLayout 本体からレンダーレスの Fx* コンポーネント群(MainScreenEffects / PermittedLayoutEffects)へ隔離し、毎秒の位置更新で約 40 フックの画面全体が再実行されるのを解消(1 フック = 1 コンポーネントに分割してあるのは、React DevTools でフック単位の再レンダーコストを計測可能にするため)
  • pictureInPictureAtom に enabled / active の narrow 派生 atom を追加し、毎秒書き換わる activityState(progress を含む)への購読巻き込みを解消
  • 設定・プラットフォームで不要なフックをマウント自体しない条件ゲートを追加: TTS 無効時の useTTS(計測時 51ms/秒の浪費 → ゼロ)、Android での useUpdateLiveActivities(iOS 専用機能の派生計算 → ゼロ)、OS 別のウェアラブル連携(useAppleWatch / useAndroidWearable)
  • AGENTS.md / docs/state-management.md に上記の規約(レンダーレス副作用ホスト・narrow 派生 atom 購読・条件マウントゲート)を追記

テスト

  • npm run lint が通ること
  • npm test が通ること
  • npm run typecheck が通ること

上記に加えて、実機(moto g05)でオートモード走行・関連画面(乗車画面 E231/SAIKYO テーマ・Privacy・路線選択・テーマ設定・自動アナウンス・表示言語・ライセンス)の巡回とランタイムエラーが無いことを確認し、React DevTools のコミット計測で before/after を比較済み(変更関連の Jest 36 スイート 406 テストもパス)。

関連Issue

スクリーンショット(任意)

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

coderabbitai Bot commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 34 minutes

Your organization has reached its usage spending cap. Adjust your spending cap in the billing tab.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: aa518a13-b2db-48b2-a19c-03162e4839d3

📥 Commits

Reviewing files that changed from the base of the PR and between 75ab7c9 and a933920.

📒 Files selected for processing (2)
  • src/components/Permitted.tsx
  • src/screens/Main.tsx
📝 Walkthrough

Walkthrough

高頻度 atom の狭い派生購読を追加し、MainScreen と PermittedLayout の副作用フックを renderless effects コンポーネントへ分離した。PiP の状態購読と各表示分岐での副作用ホストのマウントも更新した。

Changes

状態購読と副作用ホスト

Layer / File(s) Summary
PiP派生atomと運用指針
AGENTS.md, docs/state-management.md, src/store/atoms/pictureInPicture.ts
enabled と active を個別に購読する派生 atom を追加し、高頻度 atom の購読と副作用ホスト分離のルールを文書化した。
MainScreen副作用集約
src/screens/Main.tsx
副作用フックを Fx* コンポーネント群と MainScreenEffects に移し、PiP、LED、通常レイアウトの各分岐でホストをマウントするよう変更した。
PermittedLayout副作用分離
src/components/Permitted.tsx
ストア確認、方向検知、ウェアラブル連携を PermittedLayoutEffects 側へ移し、PiP の enabled/active を個別購読するよう変更した。

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

Poem

ぴょんと跳ねたら atom は細く
副作用たちは画面の外へ
PiP の灯りを別々に見つめ
Main と Permitted はすっきり整う
うさぎも安心、レンダーを駆ける
にんじん片手に、コードを祝う 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed 主変更である高頻度atomの隔離による全画面再レンダー解消を簡潔に表しています。
Description check ✅ Passed 概要・変更内容・テストが揃っており、テンプレートの必須項目は概ね満たしています。
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/style-cleanup-and-render-stability

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

@TinyKitten TinyKitten changed the title 未使用スタイルの整理と不要な再レンダーの解消でレンダリングを安定化 高頻度atom購読の隔離で位置更新ごとの全画面再レンダーを解消 Jul 15, 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.

Actionable comments posted: 2

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

Inline comments:
In `@src/components/Permitted.tsx`:
- Around line 84-98: Move useWrongDirectionDetectorEffect out of
PermittedLayoutEffects and into the appropriate FxAppleWatchInner and
FxAndroidWearableInner sibling components, so the high-frequency subscription is
isolated from the wearable host and does not trigger both wearable subtrees to
rerender. Preserve platform-specific mounting and keep the detector behavior
active only within the relevant wearable component.

In `@src/screens/Main.tsx`:
- Around line 188-212: MainScreenEffects currently mounts the Android-only
FxAndroidPictureInPicture on every platform, causing useAndroidPictureInPicture
to run on iOS. Update MainScreenEffects to conditionally mount
FxAndroidPictureInPicture only on Android, while preserving the other effects
unchanged.
🪄 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: 7f352996-53fe-41b1-9b39-22a16bee1a47

📥 Commits

Reviewing files that changed from the base of the PR and between db5df14 and 75ab7c9.

📒 Files selected for processing (5)
  • AGENTS.md
  • docs/state-management.md
  • src/components/Permitted.tsx
  • src/screens/Main.tsx
  • src/store/atoms/pictureInPicture.ts

Comment thread src/components/Permitted.tsx Resolved
Comment thread src/screens/Main.tsx Resolved
@TinyKitten

Copy link
Copy Markdown
Member Author

Fixes Applied Successfully

Fixed 2 file(s) based on 2 CodeRabbit feedback item(s).

Files modified:

  • src/components/Permitted.tsx — 高頻度購読フック(useWrongDirectionDetectorEffect / useCheckStoreVersion)をウェアラブルホストの親から sibling の Fx* コンポーネントへ分離
  • src/screens/Main.tsx — Android 専用の FxAndroidPictureInPicture を Platform.OS === 'android' の条件マウントに変更

Commit: a933920f6

The latest autofix changes are on the feature/style-cleanup-and-render-stability branch.

@TinyKitten
TinyKitten merged commit 04ff08e into dev Jul 16, 2026
5 checks passed
@TinyKitten
TinyKitten deleted the feature/style-cleanup-and-render-stability branch July 16, 2026 00:00
@TinyKitten TinyKitten mentioned this pull request Jul 16, 2026
6 of 9 tasks
TinyKitten added a commit that referenced this pull request Aug 6, 2026
高頻度atom購読の隔離(#6422)でライブアクティビティ更新フックをiOS限定でマウントするようにした際、
同じフックから呼んでいるAndroidのライブアップデート(Android 16以降)も止まっていた。
通知先を持つプラットフォームでのみマウントする条件へ変更する。


Claude-Session: https://claude.ai/code/session_01XHQB1iKjHbZLmPDKysVpnt

Co-authored-by: Claude <[email protected]>
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