Repository navigation
パフォーマンス改善: 不要な再計算とレンダーを削減 - #5547
Conversation
📝 WalkthroughWalkthrough複数コンポーネントでレンダリング最適化とロジック平坦化を導入。主にuseMemo/React.memoの追加、冗長な計算の事前算出、モジュール定数化、マッピング処理の単純化を行う変更群。 Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
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.
🧹 Nitpick comments (2)
src/components/Transfers.tsx (1)
103-122:.find()の重複呼び出しを1回にまとめることを検討してください。同じ条件
!sn.lineSymbol?.lengthで.find()を3回呼び出しています。結果を一度変数に格納することで、不要な配列走査を削減できます。♻️ 提案する修正
if (!lineSymbol.length || !stationNumber.length) { + const emptySymbolData = l.station?.stationNumbers?.find( + (sn) => !sn.lineSymbol?.length + ); const stationNumberWhenEmptySymbol = - l.station?.stationNumbers?.find((sn) => !sn.lineSymbol?.length) - ?.stationNumber ?? ''; + emptySymbolData?.stationNumber ?? ''; const lineSymbolWhenEmptySymbol = l.lineSymbols?.[0]?.symbol ?? ''; const lineSymbolColorWhenEmptySymbol = - l.station?.stationNumbers?.find((sn) => !sn.lineSymbol?.length) - ?.lineSymbolColor ?? '#000000'; + emptySymbolData?.lineSymbolColor ?? '#000000'; const lineSymbolShapeWhenEmptySymbol = - l.station?.stationNumbers?.find((sn) => !sn.lineSymbol?.length) - ?.lineSymbolShape ?? 'NOOP'; + emptySymbolData?.lineSymbolShape ?? 'NOOP';🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/components/Transfers.tsx` around lines 103 - 122, The repeated calls to l.station?.stationNumbers?.find((sn) => !sn.lineSymbol?.length) should be collapsed into a single lookup: assign the result to a const (e.g., emptySymbolSn) and then derive stationNumberWhenEmptySymbol, lineSymbolWhenEmptySymbol, lineSymbolColorWhenEmptySymbol, and lineSymbolShapeWhenEmptySymbol from that single variable with the same fallback defaults; update the return block in the same if branch so it uses emptySymbolSn instead of calling .find() three times.src/components/CommonCard.tsx (1)
125-162:SubtitleのReact.memo化は適切な最適化です。親コンポーネントの再レンダー時に、propsが変更されていない場合の不要な再レンダーを防止できます。
デバッグ時のReact DevToolsでの識別を容易にするため、
displayNameの追加を検討してください。🔧 displayName追加(オプション)
const Subtitle = memo( ({ inboundText, outboundText, numberOfLines, loading }: SubtitleProps) => { // ... component body } ); +Subtitle.displayName = 'Subtitle';🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/components/CommonCard.tsx` around lines 125 - 162, Add a displayName to the memoized component to make it easier to identify in React DevTools: after the memoized declaration of Subtitle (const Subtitle = memo(...)), set Subtitle.displayName = 'Subtitle' so the component shows a readable name in debugging tools; ensure you add this immediately after the Subtitle constant definition.
🤖 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/components/CommonCard.tsx`:
- Around line 125-162: Add a displayName to the memoized component to make it
easier to identify in React DevTools: after the memoized declaration of Subtitle
(const Subtitle = memo(...)), set Subtitle.displayName = 'Subtitle' so the
component shows a readable name in debugging tools; ensure you add this
immediately after the Subtitle constant definition.
In `@src/components/Transfers.tsx`:
- Around line 103-122: The repeated calls to
l.station?.stationNumbers?.find((sn) => !sn.lineSymbol?.length) should be
collapsed into a single lookup: assign the result to a const (e.g.,
emptySymbolSn) and then derive stationNumberWhenEmptySymbol,
lineSymbolWhenEmptySymbol, lineSymbolColorWhenEmptySymbol, and
lineSymbolShapeWhenEmptySymbol from that single variable with the same fallback
defaults; update the return block in the same if branch so it uses emptySymbolSn
instead of calling .find() three times.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 13229468-cdd9-411d-ba64-c20b5a920388
📒 Files selected for processing (3)
src/components/CommonCard.tsxsrc/components/FooterTabBar.tsxsrc/components/Transfers.tsx
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/components/SelectBoundModal.tsx (1)
244-250:nameRomanがnullの場合の考慮(任意)
normalLineDirectionTextでは.filter(Boolean)でnull値を除外していますが、ここでは除外していません。一貫性のため、同様のフィルタリングを追加することを検討してください。♻️ 提案
const inboundNamesRoman = useMemo( - () => inboundStations.map((s) => s.nameRoman).join(' and '), + () => inboundStations.map((s) => s.nameRoman).filter(Boolean).join(' and '), [inboundStations] ); const outboundNamesRoman = useMemo( - () => outboundStations.map((s) => s.nameRoman).join(' and '), + () => outboundStations.map((s) => s.nameRoman).filter(Boolean).join(' and '), [outboundStations] );🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/components/SelectBoundModal.tsx` around lines 244 - 250, inboundNamesRoman and outboundNamesRoman currently join station.nameRoman without excluding null/undefined, unlike normalLineDirectionText which uses .filter(Boolean); update the useMemo callbacks for inboundNamesRoman and outboundNamesRoman to filter out falsy nameRoman values before joining (e.g., filter by s.nameRoman or map then filter(Boolean)) so nulls are not included in the joined string, keeping the dependency arrays the same.
🤖 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/components/SelectBoundModal.tsx`:
- Around line 244-250: inboundNamesRoman and outboundNamesRoman currently join
station.nameRoman without excluding null/undefined, unlike
normalLineDirectionText which uses .filter(Boolean); update the useMemo
callbacks for inboundNamesRoman and outboundNamesRoman to filter out falsy
nameRoman values before joining (e.g., filter by s.nameRoman or map then
filter(Boolean)) so nulls are not included in the joined string, keeping the
dependency arrays the same.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: d189730e-587d-410e-b96f-30cd3af46eb3
📒 Files selected for processing (4)
src/components/PadLineMarks.tsxsrc/components/PresetCard.tsxsrc/components/RouteInfoModal.tsxsrc/components/SelectBoundModal.tsx
Summary
第1コミット: 不要な再計算とレンダーを削減
Transfers.tsx: 冗長な.map((l) => l)チェーンを削除し、1回の.map()に統合CommonCard.tsx:titleOrLineName.split()の結果をuseMemoでメモ化。SubtitleをReact.memoでラップFooterTabBar.tsx: 定数iconColorをuseMemoからコンポーネント外の定数ICON_COLORに移動第2コミット: 各コンポーネントのレンダー内計算をメモ化
PresetCard.tsx:renderTextWithSmallerParensの結果をuseMemoでメモ化(1レンダーあたり2回の呼び出しを削減)SelectBoundModal.tsx:loopLineDirectionText内の.map()を事前メモ化した文字列に置換PadLineMarks.tsx: JSX内のテキスト生成ロジックをuseMemoで事前計算RouteInfoModal.tsx:renderItem内のSet生成をstationSubtitlesMap に事前計算Regression risk
Commands executed
Test plan
https://claude.ai/code/session_01P3RbNTu7mxQvLyfzzerBFB
Summary by CodeRabbit
リリースノート