Commit f95ac92
authored
🤖 fix: prevent model selection reset in creation mode (#786)
There were two issues causing the wrong model to be used when creating
workspaces:
1. **Stale React state**: The `handleSend` callback in
`useCreationWorkspace` captured `sendMessageOptions` from
`useSendMessageOptions`, but that hook's state updates were delayed by
`requestAnimationFrame` batching in `usePersistedState`. If the user
selected a model and clicked send before the next animation frame, the
old model value would be used.
2. **Effect overwriting selection**: The useEffect that initialized the
model to the default when entering creation mode could re-run and
overwrite the user's selection if `defaultModel` changed for any reason.
**Fixes:**
- Read send options fresh from localStorage at send time using
`getSendOptionsFromStorage` instead of relying on potentially-stale
React state
- Track initialization state with a ref so the model is only set once
per entry into creation mode, not on every `defaultModel` change
Also added `mode` field to `getSendOptionsFromStorage` return value for
parity with `useSendMessageOptions`.
_Generated with `mux`_1 parent 45355f7 commit f95ac92
File tree
4 files changed
+31
-23
lines changed- src/browser
- components/ChatInput
- utils/messages
4 files changed
+31
-23
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
253 | 253 | | |
254 | 254 | | |
255 | 255 | | |
256 | | - | |
257 | | - | |
258 | | - | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
259 | 261 | | |
260 | 262 | | |
261 | | - | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
262 | 271 | | |
263 | 272 | | |
264 | 273 | | |
| |||
Lines changed: 8 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
11 | | - | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
60 | 61 | | |
61 | 62 | | |
62 | 63 | | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | 64 | | |
71 | 65 | | |
72 | 66 | | |
| |||
278 | 272 | | |
279 | 273 | | |
280 | 274 | | |
281 | | - | |
282 | | - | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | 275 | | |
287 | 276 | | |
288 | 277 | | |
| |||
376 | 365 | | |
377 | 366 | | |
378 | 367 | | |
| 368 | + | |
| 369 | + | |
379 | 370 | | |
380 | 371 | | |
381 | 372 | | |
| |||
412 | 403 | | |
413 | 404 | | |
414 | 405 | | |
415 | | - | |
416 | | - | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
417 | 410 | | |
418 | 411 | | |
419 | 412 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
98 | | - | |
99 | | - | |
| 98 | + | |
| 99 | + | |
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
| |||
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
134 | 139 | | |
135 | 140 | | |
136 | 141 | | |
| |||
188 | 193 | | |
189 | 194 | | |
190 | 195 | | |
| 196 | + | |
191 | 197 | | |
192 | 198 | | |
193 | | - | |
194 | 199 | | |
195 | 200 | | |
196 | 201 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| 63 | + | |
63 | 64 | | |
64 | 65 | | |
65 | 66 | | |
| |||
0 commit comments