mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 10:07:19 +01:00
fix(control): /control crashed on cold paint with "reading 'prompts' of null"
ControlPanel.tsx had `data!.prompts` and `data!.zellijTabs` on lines 144-145, non-null assertions that lied to the TS compiler. At runtime, every time the SWR fetch hadn't resolved yet (cold paint, slow network, post-deploy client reload) `data` was null and the page crashed before render with: Cannot read properties of null (reading 'prompts') The page was shipping a hard error in prod for any visitor whose useControlData() hook hadn't returned data by the time React tried to compute cardProps. Every other data-derived value on the page (pageState, snapshots, liveTabRows, dashboard, attention) was correctly guarded with `data ? ... : null`; this one slot wasn't. Fix: `data?.prompts ?? []` / `data?.zellijTabs ?? []`. The cardProps closure is well-formed with empty arrays. ProjectOperationsView only invokes the closure when a snapshot is selected — which requires data to be non-null — so the empty arrays are never actually walked against a real project, they're just typesafe placeholders for the initial paint. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
3e1222ba7f
commit
95fb08b197
1 file changed
+13
-2
@@ -140,9 +140,20 @@ export function ControlPanel() {
|
||||
router.replace(qs ? `${pathname}?${qs}` : pathname, { scroll: false });
|
||||
}, [focusParam, data, snapshots, liveTabRows, pathname, router, searchParams]);
|
||||
|
||||
// Build cardProps unconditionally — the closure is fine with empty arrays
|
||||
// when `data` hasn't loaded yet. ProjectOperationsView only invokes the
|
||||
// closure when there's a selected project, which requires `snapshots`,
|
||||
// which requires `data` to be non-null. So an empty-array cardProps is
|
||||
// never actually called against a real project — it's just a typesafe
|
||||
// placeholder for the initial paint.
|
||||
//
|
||||
// The previous `data!.prompts` non-null assertion lied to the TS compiler
|
||||
// and crashed in production with "Cannot read properties of null (reading
|
||||
// 'prompts')" the first time a user landed on /control before the SWR
|
||||
// fetch resolved. Worse on slow networks, every time on cold reload.
|
||||
const cardProps = buildCardProps({
|
||||
prompts: data!.prompts,
|
||||
zellijTabs: data!.zellijTabs,
|
||||
prompts: data?.prompts ?? [],
|
||||
zellijTabs: data?.zellijTabs ?? [],
|
||||
selectedAgent,
|
||||
switchableRegistry,
|
||||
inject,
|
||||
|
||||
Reference in new issue
Block a user