Skip to content

customHoldingView を必須 props にして null 混入を型で防ぐ - #87

Open
ryuuji wants to merge 1 commit into
masterfrom
task/custom-holding-view-required
Open

customHoldingView を必須 props にして null 混入を型で防ぐ#87
ryuuji wants to merge 1 commit into
masterfrom
task/custom-holding-view-required

Conversation

@ryuuji

@ryuuji ryuuji commented Aug 30, 2026

Copy link
Copy Markdown
Member

背景

src/js/view/book.tsx で差し替え可能なコンポーネントを3つ受け取っているが、扱いが揃っていなかった。
customDetailViewcustomNotFoundViewif で存在を確かめてから描画するが、customHoldingView
だけ確かめずに描画していた(非 null アサーション頼み)。

IndexdefaultPropsDefaultHoldingView を補うため通常は必ず値があるが、React の
defaultProps は値が undefined のときにしか効かない。サイト設定(window.options)が
customHoldingView に明示的に null を渡した場合は既定値が入らず、Book の描画時に
<CustomHoldingView .../>null コンポーネントとして例外になる。

対応方針

「他の2つと同じくガードして未指定時は何も描かない」か「Props で必須にして呼び出し側に保証させる」かの
どちらかを決める必要があった。所蔵リンクは検索結果の中核機能で、ガード側を選ぶとサイト設定の
不備が所蔵リンクの黙った消失として現れてしまう
(気づきにくい)。そのため後者を採用し、
根本原因(defaultPropsnull を素通しする)そのものを塞いだ。

変更内容

  • Index: Results へ渡す際に this.props.customHoldingView ?? DefaultHoldingView
    null 合体させ、undefined / null のどちらが来ても既定値を保証する
  • Results / Book: customHoldingView を必須 props(non-null)にし、Book 側の
    非 null アサーション(!)を撤去

姉妹リポジトリ(unitrad-view / unitrad-kintone-plugin / littel-ui / unitrad-ui-nagano)にも
同じ修正を入れている。

Test plan

  • npm run typecheck
  • npm test(190件全て成功)

Claude Codeで作業: https://claude.ai/code/session_01XBWJb9rhvLz6Mz6rwySUwC

Index の defaultProps は値が undefined のときしか効かないため、サイト設定
(window.options)から明示的に null が渡ると Book の描画時に例外になっていた。
Index が customHoldingView を渡す際に DefaultHoldingView へ null 合体させ、
Results / Book 側は必須 props にすることで、この経路を型で保証する。
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.

1 participant