refactor(ChatView): consolidate button state into useReducer #11452
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.
Summary
Replace 5 independent
useStatecalls (clineAsk,enableButtons,sendingDisabled,primaryButtonText,secondaryButtonText) with a singleuseReducerto eliminate partial-update race windows.Problem
When an
api_req_startedmessage arrives, button state is cleared via 5 separatesetStatecalls. React can render between updates, creating a window whereclineAskisundefinedbutprimaryButtonTextstill shows "Start New Task". Button clicks during this window are silently swallowed.A secondary issue: after
api_req_failed, theisStreamingheuristic can remain stale-true (because the lastapi_req_startedhas nocost), causing "Start New Task" clicks to route tocancelTaskinstead ofclearTask.Solution
useReducerwith 4 action types replaces the 5useStatecalls:SET_ASK_STATE: atomic update of all 5 fieldsSET_SENDING_DISABLED: partial update for retry delay / condensingSET_BUTTON_TEXT: partial update for subtask resumeRESET_WITHOUT_BUTTON_TEXT: resets without clearing button text (handleChatReset)api_req_failed/mistake_limit_reached/resume_taskchecks moved above theisStreamingguard inhandleSecondaryButtonClick, so authoritativeclineAskstate always wins over the heuristicWhat was removed
defaultfallback bandaid inhandlePrimaryButtonClickthat checkedprimaryButtonTextas a string proxy — no longer needed since atomic updates prevent the desyncVerification