Skip to content
This repository was archived by the owner on May 1, 2025. It is now read-only.

Commit 9f0d0a2

Browse files
committed
fix: assign default value to ui state, fix #95
1 parent 0282674 commit 9f0d0a2

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

stores/ui.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,11 @@ export const useUiState = defineStore('ui', () => {
1919

2020
const stateCookie = useCookie<Partial<typeof persistState>>(
2121
'nuxt-playground-ui-state',
22-
{ default: () => getLayoutDefaults(), watch: true },
22+
{ default: () => ({}), watch: true },
2323
)
2424

25-
// assign default value if missing keys on migraton
26-
const defaults = getLayoutDefaults()
27-
const keys = Object.keys(defaults) as (keyof typeof defaults)[]
28-
keys.forEach((key) => {
29-
if (stateCookie.value[key] == null)
30-
stateCookie.value[key] = defaults[key] as any
31-
})
32-
3325
// update and sync cookie with the reactive state
34-
Object.assign(persistState, stateCookie.value)
26+
Object.assign(persistState, getLayoutDefaults(), stateCookie.value)
3527
watch(persistState, () => {
3628
stateCookie.value = { ...persistState }
3729
})

0 commit comments

Comments
 (0)