Skip to content

Commit

Permalink
fix(useIDBKeyval): use toRaw instead of overriding the original object (
Browse files Browse the repository at this point in the history
#3805)

Signed-off-by: GitHub <noreply@github.com>
  • Loading branch information
ferferga committed Feb 21, 2024
1 parent ee2977b commit 1b67d96
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions packages/integrations/useIDBKeyval/index.ts
Expand Up @@ -2,7 +2,7 @@ import type { ConfigurableFlush, MaybeRefOrGetter, RemovableRef } from '@vueuse/
import { toValue } from '@vueuse/shared'
import { watchPausable } from '@vueuse/core'
import type { Ref } from 'vue-demi'
import { ref, shallowRef } from 'vue-demi'
import { ref, shallowRef, toRaw } from 'vue-demi'
import { del, get, set, update } from 'idb-keyval'

export interface UseIDBOptions extends ConfigurableFlush {
Expand Down Expand Up @@ -92,12 +92,7 @@ export function useIDBKeyval<T>(
}
else {
// IndexedDB does not support saving proxies, convert from proxy before saving
if (Array.isArray(data.value))
await update(key, () => (JSON.parse(JSON.stringify(data.value))))
else if (typeof data.value === 'object')
await update(key, () => ({ ...data.value }))
else
await update(key, () => (data.value))
await update(key, () => toRaw(data.value))
}
}
catch (e) {
Expand Down

0 comments on commit 1b67d96

Please sign in to comment.