mirror of
https://github.com/coleam00/bolt.new-any-llm
synced 2024-12-28 06:42:56 +00:00
fix: add Message Processing Throttling to Prevent Browser Crashes (#848)
This commit is contained in:
parent
80d9800aa0
commit
df6925ac07
@ -21,6 +21,7 @@ import { debounce } from '~/utils/debounce';
|
|||||||
import { useSettings } from '~/lib/hooks/useSettings';
|
import { useSettings } from '~/lib/hooks/useSettings';
|
||||||
import type { ProviderInfo } from '~/types/model';
|
import type { ProviderInfo } from '~/types/model';
|
||||||
import { useSearchParams } from '@remix-run/react';
|
import { useSearchParams } from '@remix-run/react';
|
||||||
|
import { createSampler } from '~/utils/sampler';
|
||||||
|
|
||||||
const toastAnimation = cssTransition({
|
const toastAnimation = cssTransition({
|
||||||
enter: 'animated fadeInRight',
|
enter: 'animated fadeInRight',
|
||||||
@ -77,6 +78,24 @@ export function Chat() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const processSampledMessages = createSampler(
|
||||||
|
(options: {
|
||||||
|
messages: Message[];
|
||||||
|
initialMessages: Message[];
|
||||||
|
isLoading: boolean;
|
||||||
|
parseMessages: (messages: Message[], isLoading: boolean) => void;
|
||||||
|
storeMessageHistory: (messages: Message[]) => Promise<void>;
|
||||||
|
}) => {
|
||||||
|
const { messages, initialMessages, isLoading, parseMessages, storeMessageHistory } = options;
|
||||||
|
parseMessages(messages, isLoading);
|
||||||
|
|
||||||
|
if (messages.length > initialMessages.length) {
|
||||||
|
storeMessageHistory(messages).catch((error) => toast.error(error.message));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
50,
|
||||||
|
);
|
||||||
|
|
||||||
interface ChatProps {
|
interface ChatProps {
|
||||||
initialMessages: Message[];
|
initialMessages: Message[];
|
||||||
storeMessageHistory: (messages: Message[]) => Promise<void>;
|
storeMessageHistory: (messages: Message[]) => Promise<void>;
|
||||||
@ -169,11 +188,13 @@ export const ChatImpl = memo(
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
parseMessages(messages, isLoading);
|
processSampledMessages({
|
||||||
|
messages,
|
||||||
if (messages.length > initialMessages.length) {
|
initialMessages,
|
||||||
storeMessageHistory(messages).catch((error) => toast.error(error.message));
|
isLoading,
|
||||||
}
|
parseMessages,
|
||||||
|
storeMessageHistory,
|
||||||
|
});
|
||||||
}, [messages, isLoading, parseMessages]);
|
}, [messages, isLoading, parseMessages]);
|
||||||
|
|
||||||
const scrollTextArea = () => {
|
const scrollTextArea = () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user