mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Prevent the chat UI from freezing when AI isn't configured
This commit is contained in:
1 file changed
+6
-2
@@ -1,5 +1,5 @@
|
||||
import { Decimal } from 'decimal.js';
|
||||
import { useState } from 'react';
|
||||
import { useState, useMemo } from 'react';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useAISettings } from '@/hooks/useAISettings';
|
||||
import { useCurrentUser } from '@/hooks/useCurrentUser';
|
||||
@@ -40,7 +40,7 @@ export function useProviderModels(): ModelFetchResult {
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const {
|
||||
data: models = [],
|
||||
data,
|
||||
isLoading,
|
||||
refetch,
|
||||
} = useQuery({
|
||||
@@ -147,6 +147,10 @@ export function useProviderModels(): ModelFetchResult {
|
||||
retry: false, // Don't retry on failure
|
||||
});
|
||||
|
||||
// Memoize the models array to prevent unnecessary re-renders
|
||||
// This ensures the same empty array reference is returned when there's no data
|
||||
const models = useMemo(() => data ?? [], [data]);
|
||||
|
||||
return {
|
||||
models,
|
||||
isLoading,
|
||||
|
||||
Reference in new issue
Block a user