Fix: catch sessionStorage errors for large documents (#6150)

This commit is contained in:
shamoon
2024-03-21 06:31:25 -07:00
committed by GitHub
parent 8c9fe4da06
commit ebe1479503
3 changed files with 22 additions and 6 deletions

View File

@@ -76,7 +76,10 @@ const mock = () => {
let storage: { [key: string]: string } = {}
return {
getItem: (key: string) => (key in storage ? storage[key] : null),
setItem: (key: string, value: string) => (storage[key] = value || ''),
setItem: (key: string, value: string) => {
if (value.length > 1000000) throw new Error('localStorage overflow')
storage[key] = value || ''
},
removeItem: (key: string) => delete storage[key],
clear: () => (storage = {}),
}