diff --git a/web/containers/Layout/BottomPanel/SystemMonitor/TableActiveModel/index.tsx b/web/containers/Layout/BottomPanel/SystemMonitor/TableActiveModel/index.tsx index 36cdd317f..7a7dd1e24 100644 --- a/web/containers/Layout/BottomPanel/SystemMonitor/TableActiveModel/index.tsx +++ b/web/containers/Layout/BottomPanel/SystemMonitor/TableActiveModel/index.tsx @@ -22,9 +22,7 @@ const TableActiveModel = () => {
- {activeModel && - engines && - isLocalEngine(engines, activeModel.engine) ? ( + {activeModel && isLocalEngine(engines, activeModel.engine) ? (
new Map(), []) + React.useEffect(() => { + const savedCache = JSON.parse( + window.localStorage.getItem('app-cache') || '[]' + ) + savedCache.forEach(([key, value]: [string, object]) => { + map.set(key, value) + }) + + // Before unloading the app, we write back all the data into `localStorage`. + window.addEventListener('beforeunload', () => { + const appCache = JSON.stringify(Array.from(map.entries())) + window.localStorage.setItem('app-cache', appCache) + }) + }, [map]) + + return map }}>{children} +} + +export default SWRConfigProvider diff --git a/web/containers/Providers/index.tsx b/web/containers/Providers/index.tsx index 67778e30c..bed0f07ec 100644 --- a/web/containers/Providers/index.tsx +++ b/web/containers/Providers/index.tsx @@ -4,6 +4,8 @@ import { PropsWithChildren } from 'react' import { Toaster } from 'react-hot-toast' +import { SWRConfig } from 'swr' + import EventListener from '@/containers/Providers/EventListener' import JotaiWrapper from '@/containers/Providers/Jotai' @@ -18,27 +20,30 @@ import DeepLinkListener from './DeepLinkListener' import KeyListener from './KeyListener' import Responsive from './Responsive' +import SWRConfigProvider from './SWRConfigProvider' import SettingsHandler from './SettingsHandler' const Providers = ({ children }: PropsWithChildren) => { return ( - - - - - <> - - - - - - - - {children} - - - - + + + + + + <> + + + + + + + + {children} + + + + + ) }