fix: resolve state update loop infinitive rerendering (#2017)
* fix: resolve state update loop infinitive rerendering * fix: thread creation issue
This commit is contained in:
parent
3b51f3d1aa
commit
f2e31874e1
@ -1,5 +1,5 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
|
||||
import React from 'react'
|
||||
|
||||
@ -23,15 +23,34 @@ const ServerLogs = (props: ServerLogsProps) => {
|
||||
|
||||
const clipboard = useClipboard({ timeout: 1000 })
|
||||
|
||||
useEffect(() => {
|
||||
getLogs('server').then((log) => {
|
||||
if (typeof log?.split === 'function') {
|
||||
setLogs(log.split(/\r?\n|\r|\n/g))
|
||||
}
|
||||
})
|
||||
|
||||
const updateLogs = useCallback(
|
||||
() =>
|
||||
getLogs('server').then((log) => {
|
||||
if (typeof log?.split === 'function') {
|
||||
setLogs(log.split(/\r?\n|\r|\n/g))
|
||||
}
|
||||
}),
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [logs, serverEnabled])
|
||||
[]
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
if (serverEnabled) {
|
||||
updateLogs()
|
||||
}
|
||||
}, [serverEnabled, updateLogs])
|
||||
|
||||
useEffect(() => {
|
||||
updateLogs()
|
||||
|
||||
// Log polling interval
|
||||
const intervalId = setInterval(() => {
|
||||
updateLogs()
|
||||
}, window.core?.api?.pollingInterval ?? 1000)
|
||||
|
||||
// clean up interval
|
||||
return () => clearInterval(intervalId)
|
||||
}, [updateLogs])
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@ -25,7 +25,6 @@ import useSetActiveThread from './useSetActiveThread'
|
||||
|
||||
import { extensionManager } from '@/extension'
|
||||
|
||||
import { getCurrentChatMessagesAtom } from '@/helpers/atoms/ChatMessage.atom'
|
||||
import {
|
||||
threadsAtom,
|
||||
threadStatesAtom,
|
||||
@ -57,7 +56,6 @@ export const useCreateNewThread = () => {
|
||||
const setFileUpload = useSetAtom(fileUploadAtom)
|
||||
const setSelectedModel = useSetAtom(selectedModelAtom)
|
||||
const setThreadModelParams = useSetAtom(setThreadModelParamsAtom)
|
||||
const messages = useAtomValue(getCurrentChatMessagesAtom)
|
||||
const { experimentalFeature } = useContext(FeatureToggleContext)
|
||||
|
||||
const { recommendedModel, downloadedModels } = useRecommendedModel()
|
||||
@ -71,9 +69,9 @@ export const useCreateNewThread = () => {
|
||||
const defaultModel = model ?? recommendedModel ?? downloadedModels[0]
|
||||
|
||||
// check last thread message, if there empty last message use can not create thread
|
||||
const lastMessage = threads[threads.length - 1]?.metadata?.lastMessage
|
||||
const lastMessage = threads[0]?.metadata?.lastMessage
|
||||
|
||||
if (!lastMessage && threads.length && !messages.length) {
|
||||
if (!lastMessage && threads.length) {
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
@ -7,12 +7,9 @@ import {
|
||||
|
||||
export const useLogs = () => {
|
||||
const getLogs = async (file: string) => {
|
||||
if (!(await fs.existsSync(await joinPath(['file://logs', `${file}.log`]))))
|
||||
return {}
|
||||
const logs = await fs.readFileSync(
|
||||
await joinPath(['file://logs', `${file}.log`]),
|
||||
'utf-8'
|
||||
)
|
||||
const path = await joinPath(['file://logs', `${file}.log`])
|
||||
if (!(await fs.existsSync(path))) return {}
|
||||
const logs = await fs.readFileSync(path, 'utf-8')
|
||||
|
||||
return logs
|
||||
}
|
||||
|
||||
@ -46,4 +46,5 @@ export const restAPI = {
|
||||
openExternalUrl,
|
||||
// Jan Server URL
|
||||
baseApiUrl: API_BASE_URL,
|
||||
pollingInterval: 5000,
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user