Skip to content

refactor: BacklinkPanel.tsx の targetPageName を useMemo 化 (#237)#243

Merged
ymnao merged 1 commit into
mainfrom
refactor/backlink-target-page-name-usememo-#237
Jun 26, 2026
Merged

refactor: BacklinkPanel.tsx の targetPageName を useMemo 化 (#237)#243
ymnao merged 1 commit into
mainfrom
refactor/backlink-target-page-name-usememo-#237

Conversation

@ymnao

@ymnao ymnao commented Jun 26, 2026

Copy link
Copy Markdown
Owner

概要

src/components/search/BacklinkPanel.tsxtargetPageName 計算を useMemo 化し、collapse toggle / fileTreeVersion bump / contentVersion bump 等で BacklinkPanel が再 render する度に発生していた basename().slice().normalize("NFC") の短命 string allocation を抑制する。

関連 Issue

Closes #237

移行 Stage

該当なし (Phase 2 後の内部 quality 改善)。

変更内容

  • src/components/search/BacklinkPanel.tsx: targetPageName = basename(targetFilePath).slice(0, -3).normalize("NFC")useMemo([targetFilePath]) で wrap
    • issue 提案の snippet placement (line 94) は 早期 return (line 81-89) より後ろ で hook を呼ぶ Rules of Hooks 違反になるため、targetFilePath useMemo の直後 (line 41) に移動
    • targetFilePath が null の場合は "" を返す (panel はその場合早期 return するため targetPageName は読まれない)
    • 既存 targetFilePath useMemo (line 29-34) と同じ pattern に揃え、useMemo import は既存のものを利用

動作確認

  • node_modules/.bin/tsc --noEmit clean
  • node_modules/.bin/biome check src/components/search/BacklinkPanel.tsx clean
  • node_modules/.bin/vitest run 全 2228 件 pass (2 件 skip)
  • CI で実 Electron e2e の backlink 関連 spec が pass する(ローカル不可、CI 確認に委ねる)

onNavigate(reference.filePath, reference.lineNumber, targetPageName) の渡し先 prop signature は不変、e2e mock 側 (e2e/helpers/electron-api-mock.ts) の対称対応は不要。

スクリーンショット

UI 変更なし。

`targetPageName = basename(targetFilePath).slice(0, -3).normalize("NFC")` を
毎 render 計算していたため、`normalize("NFC")` が collapse toggle / fileTreeVersion
bump / contentVersion bump 等の度に短命 string allocation を発生させていた。

`useMemo([targetFilePath])` で memoize し、targetFilePath 不変時は再計算を抑止。

issue の提案 snippet (line 94 で wrap) は早期 return (line 81-89) より後ろで
hook を呼ぶ Rules of Hooks 違反になるため、targetFilePath useMemo の直後 (line 41)
に移動。null fallback として "" を返す (panel は targetFilePath null 時に早期
return するため、targetPageName は読まれない)。
@ymnao ymnao merged commit 3727e9e into main Jun 26, 2026
9 checks passed
@ymnao ymnao deleted the refactor/backlink-target-page-name-usememo-#237 branch June 26, 2026 15:47
@ymnao ymnao mentioned this pull request Jul 5, 2026
7 tasks
ymnao added a commit that referenced this pull request Jul 5, 2026
- package.json の version を 0.6.0 → 0.7.0 に bump
- CHANGELOG.md に v0.7.0 エントリを追加 (#243#280)
  - Fixed: FileTree scroll regression (#276)、electron e2e launch teardown timeout 拡大 (#247)
  - Internal: #209 3 項目 (drift-lock 系 refactor #278/#279/#280)、settings setter 集約 (#273#277)、search/workspace/backlink 系 helper 抽出 15 件
  - Dependencies: electron 43.0.0 / p-limit 7.3.0 major bump (#275)、Dependabot 7 件 combine (#274)、pnpm-workspace.yaml overrides で @codemirror dual copy を恒久防止

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor: BacklinkPanel.tsx:94 の targetPageName を useMemo 化

1 participant