fix(chat): write correct shape in setCurrentChat - #2402
Conversation
…lure (OtterMind#2401) setCurrentChat optimistically set currentChat[page] to the whole chat object (a Record with workspace/dashboard/chat slots) instead of the ChatVO at chat[page], and chained getChatDetailById without a .catch — so a fetch rejection left the wrong-shape Record in the slot, making currentChat[page].id/.title/.chatDetails undefined (blank title, empty list) until a later successful fetch. Set [page]: chat[page] and restore the slot to chat[page] on fetch failure. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: liuhy <liuhongyu@apache.org>
There was a problem hiding this comment.
Pull request overview
Note
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Fixes an incorrect currentChat state shape being written during optimistic updates and ensures fetch failures don’t leave subscribers reading undefined fields for the current chat.
Changes:
- Write
currentChat[page] = chat[page](aChatVO) instead ofchat(the whole Record) in theifbranch. - Add a
.catch()to restore state and clear chat details whengetChatDetailByIdfails.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
openai0229
left a comment
There was a problem hiding this comment.
Reviewed the final state-management change after syncing with the latest main. It writes the correct ChatVO shape, merges against current Zustand state, clears stale details before fetching, and preserves promise rejection for callers. Focused ESLint passes.
What
setCurrentChatoptimistically wrotecurrentChat[page] = chat(the whole Record) instead ofchat[page](theChatVO). That left the slot with the wrong shape while details loaded, socurrentChat[page].id/.title/.chatDetailscould beundefined.Location
src/store/chat/slices/common/action.ts:150-169Fix
[page]: chat[page]instead of the wholechatRecord.currentChatchanges are merged against the latest state.getChatDetailByIdrejections observable to callers.resetChatDetails(page)already clears stale details before the request starts, so no failure catch/state rewrite is needed.Verification
elsebranch already useschat[page]; both branches now use the same shape.state.currentChat.Fixes #2401
🤖 Generated with Claude Code