Repository navigation
MAINT Extract ChatWindow send workflow into a reducer (#2652) - #4162
Open
Julio César Suástegui (juliosuas) wants to merge 1 commit into
Open
Julio César Suástegui (juliosuas) wants to merge 1 commit into
Julio César Suástegui (juliosuas) wants to merge 1 commit into
Conversation
Final step of microsoft#2652, after microsoft#3310 (loading), microsoft#3369 (score, objective and export) and microsoft#3812 (copy and branch). The send workflow's rendered state (per-conversation send and scoring locks, send issues, failed-send recoveries, repeated-send progress and the undoable last send) now moves through an explicit reducer with typed actions in utils/chatSendState.ts. useChatSendState owns that reducer plus the synchronous locks the conversation loader reads; useChatSend owns the commands: optimistic messages, attachment and conversion capture, lazy attack creation, progress tracking, refresh after unknown delivery and preparation-draft restore. Its input is grouped by seam (route, readiness, request, composer, loader, callbacks), and ChatWindow passes the conversation loader through unchanged. No prop, UI, accessibility, request payload or navigation changes. Reducer transitions and the hook's regression cases (duplicate sends, two conversations sending independently, optimistic prompts on return to an in-flight conversation, first-send conversation creation, unknown delivery, pre-submission failures, converted pieces) have focused tests. Refs microsoft#2652
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the send-workflow extraction into a reducer and focused hooks.
No open issues 🎉
What changed in this PR
Continues #2652 by extracting ChatWindow’s send workflow into a reducer and focused hooks, building on the earlier loading, mutation/export, and copy/branch extractions.
Changes:
- Centralizes rendered send state in a typed reducer, including locks, recovery, repeated-send progress, and undo.
- Moves send orchestration into
useChatSendand synchronous tracking intouseChatSendState, leaving ChatWindow to compose them. - Adds focused reducer and hook tests for state transitions, independent sends, optimistic messages, recovery, and conversions.
| File | Description |
|---|---|
frontend/src/utils/chatSendState.ts |
Defines send state, actions, reducer, and recovery helpers. |
frontend/src/utils/chatSendState.test.ts |
Tests reducer transitions and persisted recovery handling. |
frontend/src/hooks/useChatSend.ts |
Owns send tracking, submission, progress, and recovery commands. |
frontend/src/hooks/useChatSend.test.ts |
Tests send orchestration and key failure paths. |
frontend/src/components/Chat/ChatWindow.tsx |
Replaces inline send orchestration with hook composition. |
Review effort: Balanced
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Related to #2652. Final step: the send workflow as an explicit reducer plus the ChatWindow composition cleanup, as scoped in the issue thread. Loading landed in #3310, score/objective/export in #3369, and copy/branch in #3812.
frontend/src/utils/chatSendState.ts: reducer with typed actions for the send workflow's rendered state: per-conversation send and scoring locks, send issues, failed-send recoveries, repeated-send progress and the undoable last send.frontend/src/hooks/useChatSend.ts:useChatSendStateowns that reducer plus the synchronous locks the conversation loader reads;useChatSendowns the commands (optimistic messages, attachment and conversion capture, lazy attack creation, progress tracking, refresh after unknown delivery, preparation-draft restore). Its input is grouped by seam (tracking,route,readiness,request,composer,loader,callbacks) with typed, documented interfaces, followinguseConversationCopy.ChatWindow.tsx: composes the two hooks instead of inlining the send workflow (3,045 to 2,208 lines). The conversation loader result is passed through unchanged.No prop, UI, accessibility, request payload or navigation changes.
Open questions for review:
useChatSendcan consume the loader. Is that boundary acceptable, or would you prefer a different split?Tests and Documentation
chatSendState.test.ts(reducer transitions) anduseChatSend.test.ts(duplicate sends, two conversations sending independently, optimistic prompts on return to an in-flight conversation, first-send conversation creation, unknown delivery, pre-submission failures, converted pieces): 31/31.tsc --noEmit: 0 errors. Lint: 0 errors.npm run buildpasses.e2e/onboarding-tour.spec.tsfail identically on main (935afa8).AI-assisted; reviewed and tested by me.