Skip to content

bug(chat): setCurrentChat writes the wrong shape and lacks a catch on fetch failure #2401

Description

@Aias00

Description

setCurrentChat optimistically writes the whole chat object (a Record with workspace/dashboard/chat slots) into currentChat[page] instead of the ChatVO at chat[page], then fetches the detail and overwrites currentChat[page] in .then(). There is no .catch(): if the detail fetch rejects, currentChat[page] keeps the wrong-shape whole-chat Record, so readers of currentChat[page].id / .title / .chatDetails (e.g. the chat menu list) see undefined → blank title and empty list until the user picks a chat whose fetch succeeds. The wrong-shape set is also published to subscribers before the async resolves.

Location

chat2db-community-client/src/store/chat/slices/common/action.ts:150-169

if (chat[page]?.id) {
  const { id } = chat[page];
  set({ currentChat: { ...currentChat, [page]: chat } });   // ← whole `chat`, should be chat[page]
  return chatService.getChatDetailById({ pageSize: 5, id: id! })
    .then((res) => { if (res) { set({ currentChat: { ...currentChat, [page]: res } }); ... } });  // ← no .catch
}

The else branch (line 171) correctly uses chat[page].

Impact

Fetch failure leaves a wrong-shape Record in currentChat[page]; chat title blank, list empty until next successful fetch.

Suggested fix

Set [page]: chat[page] (not chat), and add a .catch() that restores the slot to chat[page] and clears chat details.

Related existing

None. #2346 (rename leaves stale top-level metadata) is a different path/mechanism.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions