mirror of
https://github.com/Kong/insomnia.git
synced 2026-08-04 11:52:33 -04:00
fix: prevent stale features from race condition in AISettings useEffect
Reset to fallbackFeatures when fetch condition is not met, and use a cancelled flag to ignore responses from outdated requests after unmount or dependency change. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -20,11 +20,15 @@ export const AISettings = () => {
|
||||
const [features, setFeatures] = useState<FeatureList>(fallbackFeatures);
|
||||
|
||||
useEffect(() => {
|
||||
if (organizationId && userSession.id && !models.organization.isScratchpadOrganizationId(organizationId)) {
|
||||
getOrganizationFeatures({ organizationId, sessionId: userSession.id })
|
||||
.then(res => setFeatures(res?.features || fallbackFeatures))
|
||||
.catch(() => setFeatures(fallbackFeatures));
|
||||
if (!organizationId || !userSession.id || models.organization.isScratchpadOrganizationId(organizationId)) {
|
||||
setFeatures(fallbackFeatures);
|
||||
return;
|
||||
}
|
||||
let cancelled = false;
|
||||
getOrganizationFeatures({ organizationId, sessionId: userSession.id })
|
||||
.then(res => { if (!cancelled) { setFeatures(res?.features || fallbackFeatures); } })
|
||||
.catch(() => { if (!cancelled) { setFeatures(fallbackFeatures); } });
|
||||
return () => { cancelled = true; };
|
||||
}, [organizationId, userSession.id]);
|
||||
const [currentLLM, setCurrentLLM] = useState<LLMConfig | null>(null);
|
||||
const [selectedBackend, setSelectedBackend] = useState<LLMBackend>('gguf');
|
||||
|
||||
Reference in New Issue
Block a user