Skip to content

Commit

Permalink
fix: performance issue with atom storage persistence
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-jan committed Dec 17, 2024
1 parent f2db317 commit 2b0a4c4
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions web/helpers/atoms/ChatMessage.atom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from '@janhq/core'
import { atom } from 'jotai'

import { atomWithStorage } from 'jotai/utils'
import { atomWithStorage, createJSONStorage } from 'jotai/utils'

import {
getActiveThreadIdAtom,
Expand All @@ -16,13 +16,16 @@ import {
import { TokenSpeed } from '@/types/token'

const CHAT_MESSAGE_NAME = 'chatMessages'
const storage = createJSONStorage<Record<string, ThreadMessage[]>>(
() => sessionStorage
)
/**
* Stores all chat messages for all threads
*/
export const chatMessages = atomWithStorage<Record<string, ThreadMessage[]>>(
CHAT_MESSAGE_NAME,
{},
undefined,
storage,
{ getOnInit: true }
)

Expand Down

0 comments on commit 2b0a4c4

Please sign in to comment.