fix(api): return empty arrays not null for empty lists (frontend null.length crash)

Root cause: store List* methods used 'var out []T' which stays nil on empty
result sets and serializes to JSON null; the SPA then crashed on .length/.map
(e.g. endpoints.length on the Tasks page right after deploy). Return []T{}
at the source; coerce null->[] on the frontend load sites as defense-in-depth.
Regression test asserts List* are non-nil when empty.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MMHQTtnQtQqL8muAXHr9kd
This commit is contained in:
2026-07-02 09:04:33 +07:00
parent d87a8c57ad
commit 7eff28053a
6 changed files with 44 additions and 6 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ export function Endpoints() {
function reload() {
listEndpoints()
.then(setEndpoints)
.then((e) => setEndpoints(e ?? []))
.catch((e) => setError(String(e.message || e)))
}
+2 -2
View File
@@ -13,13 +13,13 @@ export function Tasks() {
function reload() {
listTasks()
.then(setTasks)
.then((t) => setTasks(t ?? []))
.catch((e: unknown) => setError(e instanceof Error ? e.message : 'Failed to load tasks'))
}
useEffect(() => {
reload()
listEndpoints().then(setEndpoints).catch(() => {})
listEndpoints().then((e) => setEndpoints(e ?? [])).catch(() => {})
}, [])
async function submit(e: FormEvent) {