mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-05-22 11:08:50 +00:00
Migrate Chat Persistence from localStorage to IndexedDB to Fix QuotaExceededError (#560)
This commit is contained in:
parent
807c3e23cf
commit
7e692f9862
4 changed files with 31 additions and 1 deletions
|
|
@ -59,6 +59,7 @@
|
|||
"embla-carousel-autoplay": "^8.6.0",
|
||||
"embla-carousel-react": "^8.6.0",
|
||||
"framer-motion": "^12.23.12",
|
||||
"idb-keyval": "^6.2.2",
|
||||
"is-hotkey": "^0.2.0",
|
||||
"lucide-react": "^0.525.0",
|
||||
"masonic": "^4.1.0",
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import type { UIMessage } from "@ai-sdk/react"
|
||||
import { create } from "zustand"
|
||||
import { persist } from "zustand/middleware"
|
||||
import { persist, createJSONStorage } from "zustand/middleware"
|
||||
import { useCallback } from "react"
|
||||
import { indexedDBStorage } from "./indexeddb-storage"
|
||||
|
||||
/**
|
||||
* Deep equality check for UIMessage arrays to prevent unnecessary state updates
|
||||
|
|
@ -175,6 +176,7 @@ export const usePersistentChatStore = create<ConversationsStoreState>()(
|
|||
}),
|
||||
{
|
||||
name: "supermemory-chats",
|
||||
storage: createJSONStorage(() => indexedDBStorage),
|
||||
},
|
||||
),
|
||||
)
|
||||
|
|
|
|||
24
apps/web/stores/indexeddb-storage.ts
Normal file
24
apps/web/stores/indexeddb-storage.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import { get, set, del } from 'idb-keyval';
|
||||
|
||||
export const indexedDBStorage = {
|
||||
getItem: async (name: string) => {
|
||||
let value = await get(name);
|
||||
if (value !== undefined) {
|
||||
return value;
|
||||
}
|
||||
// Migrate from localStorage if exists
|
||||
value = localStorage.getItem(name);
|
||||
if (value !== null) {
|
||||
await set(name, value);
|
||||
localStorage.removeItem(name);
|
||||
return value;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
setItem: async (name: string, value: string) => {
|
||||
await set(name, value);
|
||||
},
|
||||
removeItem: async (name: string) => {
|
||||
await del(name);
|
||||
},
|
||||
};
|
||||
3
bun.lock
3
bun.lock
|
|
@ -140,6 +140,7 @@
|
|||
"embla-carousel-autoplay": "^8.6.0",
|
||||
"embla-carousel-react": "^8.6.0",
|
||||
"framer-motion": "^12.23.12",
|
||||
"idb-keyval": "^6.2.2",
|
||||
"is-hotkey": "^0.2.0",
|
||||
"lucide-react": "^0.525.0",
|
||||
"masonic": "^4.1.0",
|
||||
|
|
@ -2884,6 +2885,8 @@
|
|||
|
||||
"iconv-lite": ["iconv-lite@0.4.24", "", { "dependencies": { "safer-buffer": ">= 2.1.2 < 3" } }, "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA=="],
|
||||
|
||||
"idb-keyval": ["idb-keyval@6.2.2", "", {}, "sha512-yjD9nARJ/jb1g+CvD0tlhUHOrJ9Sy0P8T9MF3YaLlHnSRpwPfpTX0XIvpmw3gAJUmEu3FiICLBDPXVwyEvrleg=="],
|
||||
|
||||
"ieee754": ["ieee754@1.2.1", "", {}, "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA=="],
|
||||
|
||||
"ignore": ["ignore@5.3.2", "", {}, "sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g=="],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue