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

Commit 0282674

Browse files
committed
fix: update cookie default value
1 parent a17a780 commit 0282674

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

stores/ui.ts

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

2020
const stateCookie = useCookie<Partial<typeof persistState>>(
2121
'nuxt-playground-ui-state',
22-
{ default: () => ({}), watch: true },
22+
{ default: () => getLayoutDefaults(), 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+
33+
// update and sync cookie with the reactive state
2534
Object.assign(persistState, stateCookie.value)
2635
watch(persistState, () => {
2736
stateCookie.value = { ...persistState }

0 commit comments

Comments
 (0)