From 518b794428fb971b289895f6170aa85c40850278 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 13 Jun 2026 22:29:45 +0000 Subject: [PATCH] fix: guard isConvoActive against unloaded convo Fixes a TypeError ('Cannot read property view of undefined') in MessagesList getFooterState. The convo status can transition into an active state (e.g. Backgrounded when the screen blurs before setup() resolves) while this.convo is still undefined. The snapshot builds those states with a non-null assertion (this.convo!), so isConvoActive returned true and the conversation rendered MessagesList against an undefined convo. Require convo to be present, matching the non-optional convo field on every ActiveConvoStates member. --- src/state/messages/convo/util.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/state/messages/convo/util.ts b/src/state/messages/convo/util.ts index 5301d10bbb..8a2d0b71ef 100644 --- a/src/state/messages/convo/util.ts +++ b/src/state/messages/convo/util.ts @@ -21,12 +21,19 @@ export type ActiveConvoStates = * Checks if a `Convo` has a `status` that is "active", meaning the chat is * loaded and ready to be used, or its in a suspended or background state, and * ready for resumption. + * + * The `convo` object must also be present. The status can transition into an + * active state before the convo has finished loading (e.g. `Initializing` + * receives a `Background` event before `setup()` resolves), and every + * `ActiveConvoStates` member declares `convo` as non-optional, so we guard + * against that race here rather than crashing downstream consumers. */ export function isConvoActive(convo: ConvoState): convo is ActiveConvoStates { return ( - convo.status === ConvoStatus.Ready || - convo.status === ConvoStatus.Backgrounded || - convo.status === ConvoStatus.Suspended || - convo.status === ConvoStatus.Disabled + convo.convo !== undefined && + (convo.status === ConvoStatus.Ready || + convo.status === ConvoStatus.Backgrounded || + convo.status === ConvoStatus.Suspended || + convo.status === ConvoStatus.Disabled) ) }