fix
This commit is contained in:
1 parent
cd107604a9
commit
f4c768df29
6 files changed
+37
-25
No files matched your search
@@ -50,6 +50,19 @@ const resolvePersistOptions = (persist: PersistOption | undefined) => {
|
||||
return persist
|
||||
}
|
||||
|
||||
const trimStringValuesDeep = (value: unknown): unknown => {
|
||||
if (typeof value === 'string') return value.trim()
|
||||
if (Array.isArray(value)) return value.map(item => trimStringValuesDeep(item))
|
||||
if (value && typeof value === 'object') {
|
||||
const normalized: Record<string, unknown> = {}
|
||||
for (const [key, child] of Object.entries(value as Record<string, unknown>)) {
|
||||
normalized[key] = trimStringValuesDeep(child)
|
||||
}
|
||||
return normalized
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
export default (config?: PiniaStorageConfig) => {
|
||||
const finalConfig = { ...baseConfig, ...(config || {}) }
|
||||
const { mode = 'single', debounce = 300, ...forageConfig } = finalConfig
|
||||
@@ -67,7 +80,10 @@ export default (config?: PiniaStorageConfig) => {
|
||||
let timer: ReturnType<typeof setTimeout> | null = null
|
||||
let hydrating = false
|
||||
let userMutatedBeforeHydrate = false
|
||||
const writeState = (state: unknown) => lf.setItem(key, JSON.parse(JSON.stringify(state)))
|
||||
const writeState = (state: unknown) => {
|
||||
const clonedState = JSON.parse(JSON.stringify(state))
|
||||
return lf.setItem(key, trimStringValuesDeep(clonedState))
|
||||
}
|
||||
const storeExt = context.store as typeof context.store & PersistStoreExt
|
||||
|
||||
storeExt.$persistNow = async () => {
|
||||
|
||||
Reference in new issue
Block a user