Skip to content

Commit 04d56ec

Browse files
committed
🤖 fix: prevent model selection reset in creation mode
The useEffect that initialized the project-scoped model in creation mode was incorrectly re-running whenever `defaultModel` changed. This meant if a user selected a different model from the dropdown and then any storage event triggered a defaultModel update, their selection would be silently overwritten with the favorite/default model. Fix: Track initialization state with a ref so the model is only set once per entry into creation mode, not on every defaultModel change. Reset the ref when leaving creation mode so re-entering properly initializes. _Generated with `mux`_
1 parent d7560e1 commit 04d56ec

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/browser/components/ChatInput/index.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,21 @@ export const ChatInput: React.FC<ChatInputProps> = (props) => {
182182
[storageKeys.modelKey, addModel]
183183
);
184184

185-
// When entering creation mode (or when the default model changes), reset the
186-
// project-scoped model to the explicit default so manual picks don't bleed
187-
// into subsequent creation flows.
185+
// When entering creation mode, initialize the project-scoped model to the
186+
// default so previous manual picks don't bleed into new creation flows.
187+
// Only runs once per creation session (not when defaultModel changes, which
188+
// would clobber the user's intentional model selection).
189+
const creationModelInitialized = useRef<string | null>(null);
188190
useEffect(() => {
189191
if (variant === "creation" && defaultModel) {
190-
updatePersistedState(storageKeys.modelKey, defaultModel);
192+
// Only initialize once per project scope
193+
if (creationModelInitialized.current !== storageKeys.modelKey) {
194+
creationModelInitialized.current = storageKeys.modelKey;
195+
updatePersistedState(storageKeys.modelKey, defaultModel);
196+
}
197+
} else if (variant !== "creation") {
198+
// Reset when leaving creation mode so re-entering triggers initialization
199+
creationModelInitialized.current = null;
191200
}
192201
}, [variant, defaultModel, storageKeys.modelKey]);
193202

0 commit comments

Comments
 (0)