Commit 7feb2df
committed
🤖 fix: prevent model selection race condition in creation mode
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 d7560e1 commit 7feb2df
File tree
4 files changed
+31
-22
lines changed- src/browser
- components/ChatInput
- utils/messages
4 files changed
+31
-22
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
185 | | - | |
186 | | - | |
187 | | - | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
188 | 190 | | |
189 | 191 | | |
190 | | - | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
191 | 200 | | |
192 | 201 | | |
193 | 202 | | |
| |||
Lines changed: 8 additions & 14 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 | | |
| |||
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | 60 | | |
63 | 61 | | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | 62 | | |
68 | 63 | | |
69 | 64 | | |
| |||
86 | 81 | | |
87 | 82 | | |
88 | 83 | | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | 84 | | |
95 | 85 | | |
96 | 86 | | |
| |||
180 | 170 | | |
181 | 171 | | |
182 | 172 | | |
| 173 | + | |
| 174 | + | |
183 | 175 | | |
184 | 176 | | |
185 | 177 | | |
| |||
207 | 199 | | |
208 | 200 | | |
209 | 201 | | |
210 | | - | |
211 | | - | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
212 | 206 | | |
213 | 207 | | |
214 | 208 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
75 | | - | |
76 | | - | |
| 75 | + | |
| 76 | + | |
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
111 | 116 | | |
112 | 117 | | |
113 | 118 | | |
| |||
158 | 163 | | |
159 | 164 | | |
160 | 165 | | |
| 166 | + | |
161 | 167 | | |
162 | 168 | | |
163 | | - | |
164 | 169 | | |
165 | 170 | | |
166 | 171 | | |
| |||
| 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