From 3eba7b64e2e24d6c0a4a78237249d643c8fbf20e Mon Sep 17 00:00:00 2001 From: dongsheng123132 <38004547@qq.com> Date: Wed, 24 Jun 2026 10:51:14 +0800 Subject: [PATCH] fix: guard against undefined updatedAt when sorting provider accounts The provider-account comparators call `updatedAt.localeCompare(...)` assuming `updatedAt` is always a string. When a persisted account is missing `updatedAt` (e.g. a record written by an external tool / migration / a hand-edited clawx-providers.json), the value is `undefined` and the whole renderer crashes at the error boundary: TypeError: Cannot read properties of undefined (reading 'localeCompare') at Array.sort () at buildConfiguredModelOptions / buildRuntimeProviderOptions (useMemo) `listProviderAccounts()` returns stored accounts verbatim without normalization, so a single bad record takes down both the Chat page (model picker) and the Agents page. Make the three `updatedAt` comparators null-safe with `?? ''`. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/lib/model-options.ts | 4 ++-- src/lib/provider-accounts.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/model-options.ts b/src/lib/model-options.ts index b3f235b80..a0d0b5b1f 100644 --- a/src/lib/model-options.ts +++ b/src/lib/model-options.ts @@ -99,7 +99,7 @@ export function buildRuntimeProviderOptions( .sort((left, right) => { if (left.id === providerDefaultAccountId) return -1; if (right.id === providerDefaultAccountId) return 1; - return right.updatedAt.localeCompare(left.updatedAt); + return (right.updatedAt ?? '').localeCompare(left.updatedAt ?? ''); }); const deduped = new Map(); @@ -142,7 +142,7 @@ export function buildConfiguredModelOptions( .sort((left, right) => { if (left.id === providerDefaultAccountId) return -1; if (right.id === providerDefaultAccountId) return 1; - return right.updatedAt.localeCompare(left.updatedAt); + return (right.updatedAt ?? '').localeCompare(left.updatedAt ?? ''); }); const deduped = new Map(); diff --git a/src/lib/provider-accounts.ts b/src/lib/provider-accounts.ts index 3b6348e6b..57c1ba469 100644 --- a/src/lib/provider-accounts.ts +++ b/src/lib/provider-accounts.ts @@ -189,7 +189,7 @@ export function buildProviderListItems( .sort((left, right) => { if (left.account.id === defaultAccountId) return -1; if (right.account.id === defaultAccountId) return 1; - return right.account.updatedAt.localeCompare(left.account.updatedAt); + return (right.account.updatedAt ?? '').localeCompare(left.account.updatedAt ?? ''); }); }