Skip to content

Commit d7c727e

Browse files
committed
fix: sync warning with indirect model changes (mode/agent switch)
WorkspaceModeAISync can update pendingModel via localStorage when mode/agent changes. Add effect to detect these external changes and recompute warning.
1 parent 82532db commit d7c727e

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

src/browser/hooks/useContextSwitchWarning.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,18 @@ export function useContextSwitchWarning(
8181
setWarning(null);
8282
}, []);
8383

84+
// Sync with indirect model changes (e.g., WorkspaceModeAISync updating model on mode/agent change).
85+
// Effect is appropriate: pendingModel comes from usePersistedState (localStorage), and external
86+
// components like WorkspaceModeAISync can update it without going through handleModelChange.
87+
useEffect(() => {
88+
const prevModel = prevPendingModelRef.current;
89+
if (prevModel !== pendingModel) {
90+
prevPendingModelRef.current = pendingModel;
91+
const tokens = getCurrentTokens();
92+
setWarning(tokens > 0 ? checkContextSwitch(tokens, pendingModel, prevModel, use1M) : null);
93+
}
94+
}, [pendingModel, getCurrentTokens, use1M]);
95+
8496
// Sync with 1M toggle changes from ProviderOptionsContext.
8597
// Effect is appropriate here: we're syncing with an external context (not our own state),
8698
// and the toggle change happens in ModelSettings which can't directly call our handlers.

0 commit comments

Comments
 (0)