Repository navigation
Commit bbe4258
fix(plugin-chatbot): a send clears only the composer's message box, so the picked model survives it (#38106)
<!-- claude-projects-attribution: {"github_login":"os-tesla"} -->
_Requested by **Tesla** · [project
thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6Jao2F5jFXXMeaD95BAtSDpyiW)_
Fixes #37831
repo:objectstack#3 · os-tesla · session_01L9qibxaAB2c4Epy2EEZxDf
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 在 AI
侧栏里换了模型再提问,以后的问题会一直用这个模型,直到你自己再换。以前每次发送都会把选择悄悄改回默认模型,下一个问题就用默认模型回答、按默认倍率计费。
- 属于问 AI 对话体验这条线:用户选定的设置不能被悄悄丢掉。全页聊天用的是同一个输入框,同一处修复覆盖它,但没有单独测。
-
只改输入框发送时清空文字的方式:以前重置整张表单,现在只清空输入框本身,其他表单控件不再被一起重置。改错的话,最坏是发送后输入框里的文字没清掉,可以直接撤回。
- 无
## What changes
- `ui/packages/plugin-chatbot/src/elements/prompt-input.tsx`:
`handleSubmit` no longer calls `form.reset()` to clear the composer. It
sets the `message` field back to its `defaultValue`, which is what the
reset gave that field, and leaves every other control in the form alone.
- `patch` changeset for `@object-ui/plugin-chatbot`.
## Why
The composer's model picker (`chat/ModelPicker.tsx`) is the shared Radix
`Select`, and it sits inside the composer's `<form>`. Radix Select 2.3.7
listens for the `reset` event of the form it belongs to and answers it
with `setValue(initialValueRef.current)`, the value it had on its FIRST
render (`@radix-ui/react-select` `dist/index.mjs`, the effect that adds
the `reset` listener). For the picker that is the default model's index.
Because the picker is controlled, `setValue` calls `onValueChange`, so
`ModelPicker` calls `onPick(defaultId)` and the host that holds the pick
(`ChatDockConversation`, ADR-0028) records the default model. Every send
therefore put the pick back to the default: the send itself still
carried the picked model (read before the reset landed), and the next
one carried the default.
The earlier attempt on this card (report 7213606537) mocked
`ChatbotEnhanced` and called `onSendMessage` directly, so the form
submit, and with it the reset, never ran. Its other finding still holds:
`ChatDockConversation` is not remounted around a turn.
## Tests
`ui/packages/plugin-chatbot/src/__tests__/ChatbotEnhanced.modelPicker-11865.test.tsx`,
new top-level `describe` "a picked model survives the composer's send
(objectstack#37831)". The host holds the pick, as every chat host does,
and each send goes through the real form submit (Enter in the box):
- picked: after each of two sends the picker still shows the picked
model; `onModelChange` received only the user's pick; both sends carried
the picked model; the box is empty after the send;
- CONTROL, no pick: the first model is in force before and after a send,
nothing is written, the box is empty.
<details><summary>Readings at eb2e26d (base origin/main
f72f335)</summary>
- Premise at f72f335 through a throwaway probe (deleted; copy kept in
the project folder): the real `ChatbotEnhanced`, a pick made in the UI,
then a form submit. `onModelChange` received `["m_picked","m_default"]`
and the picker showed Default after the send; CONTROL (no pick) wrote
nothing; with the `reset` event swallowed in the window's capture phase
and nothing else changed, the pick survived (`writes: ["m_picked"]`).
- Ablation on the committed fix: `form.reset()` put back in
`handleSubmit`, then `vitest run
packages/plugin-chatbot/src/__tests__/ChatbotEnhanced.modelPicker-11865.test.tsx`:
`Tests 1 failed | 21 passed (22)`, the failure being the picked row
(`expected 'GPT-4o mini' to be 'Claude 3.5'`), the CONTROL row green.
Restored with `git restore --source=HEAD --staged --worktree`, `git
status --porcelain` empty, `Tests 22 passed (22)`.
- `pnpm --filter @object-ui/plugin-chatbot test`: `Test Files 76 passed
(76)`, `Tests 731 passed (731)`. `type-check` exit 0. `eslint` on the
two changed files: 0 errors, and the same 11 warnings as the file on
`main` (all pre-existing, none on a changed line).
- `vitest run packages/app-shell/src/console/ai
packages/app-shell/src/layout` (the hosts that render this composer):
`Test Files 210 passed (210)`, `Tests 1796 passed (1796)`.
- `dispatch-gates --commands` at eb2e26d: 39 derived, 39 run, all exit
0 (`pnpm --dir ui exec vitest run scripts/` was killed once by the
container's memory limit while another run was going, then re-run alone:
`Test Files 172 passed | 2 skipped (174)`, exit 0). `origin/main` is 2
commits ahead, neither touching `ui/packages/plugin-chatbot`.
</details>
## Acceptance notes
- Not changed, file surface fenced by the claim: two comments in
`ChatbotEnhanced.tsx` (in `sendTyped` and above the send-failure restore
effect) still say "the composer's own form.reset clears the box
optimistically". The box is still cleared optimistically at the same
moment, now by the field reset, so both comments stay true in effect;
the word `form.reset` in them is stale. A follow-up can reword them when
that file is next touched.
- The full-page chat (`AiChatPage`) and the app Ask page render the same
composer, so they take the same fix. Neither was measured separately.
## Verification
Read first (by risk):
1. `ui/packages/plugin-chatbot/src/elements/prompt-input.tsx`:
`handleSubmit`, the clear before the blob conversion.
2. The new `describe` at the end of
`ChatbotEnhanced.modelPicker-11865.test.tsx`.
Two-minute check: `cd ui && pnpm exec vitest run
packages/plugin-chatbot/src/__tests__/ChatbotEnhanced.modelPicker-11865.test.tsx`
shows 22 passing; put `form.reset();` back in place of the field clear
in `handleSubmit` and the same command shows the picked row failing.
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
(not touched)
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` passes.
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request.
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset.
- [x] 6. `packages/spec` touched: its generated artifacts are
regenerated and committed. (not touched)
- [x] 7. No hand edits to `content/docs/references/`,
`packages/*/CHANGELOG.md` or `content/docs/releases/`.
- [x] 8. Title, body and comments are in English.
- [x] The *Before Submitting* list in CONTRIBUTING.md is done.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01L9qibxaAB2c4Epy2EEZxDf)_
Co-authored-by: Claude <noreply@anthropic.com>1 parent 630a609 commit bbe4258
3 files changed
Lines changed: 91 additions & 4 deletions
File tree
- .changeset
- ui/packages/plugin-chatbot/src
- __tests__
- elements
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
| 45 | + | |
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| |||
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
791 | 791 | | |
792 | 792 | | |
793 | 793 | | |
794 | | - | |
795 | | - | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
796 | 802 | | |
797 | | - | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
798 | 807 | | |
799 | 808 | | |
800 | 809 | | |
| |||
0 commit comments