Skip to content

Commit 7afd857

Browse files
committed
fix(ClientDB): drop LocalStorage
1 parent c76c5a7 commit 7afd857

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

src/runtime/composables/client-db.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Storage } from 'unstorage'
22
// @ts-ignore
3-
import LSDriver from 'unstorage/drivers/localstorage'
3+
import memoryDriver from 'unstorage/drivers/memory'
44
import { createStorage, prefixStorage } from 'unstorage'
55
import { useRuntimeConfig, useCookie } from '#app'
66
import { withBase } from 'ufo'
@@ -11,7 +11,7 @@ import { createNav } from '../server/navigation'
1111

1212
const withContentBase = url => withBase(url, '/api/' + useRuntimeConfig().public.content.base)
1313

14-
export const contentStorage = prefixStorage(createStorage({ driver: LSDriver() }), '@content')
14+
export const contentStorage = prefixStorage(createStorage({ driver: memoryDriver() }), '@content')
1515

1616
export const getPreview = () => {
1717
return useCookie('previewToken').value

src/runtime/preview/preview-plugin.ts

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { createApp } from 'vue'
2+
import { contentStorage } from '../composables/client-db'
23
import { defineNuxtPlugin, useRoute, useCookie, refreshNuxtData, useRuntimeConfig } from '#imports'
34
import { ContentPreviewMode } from '#components'
45

@@ -14,12 +15,8 @@ export default defineNuxtPlugin((nuxt) => {
1415
}
1516
})
1617
// Remove previous preview data
17-
Object.keys(window.localStorage)
18-
.forEach((key) => {
19-
if (key.startsWith(`@content:${token}:`)) {
20-
window.localStorage.removeItem(key)
21-
}
22-
})
18+
const keys = await contentStorage.getKeys(`${token}:`)
19+
keys.forEach(key => contentStorage.removeItem(key))
2320

2421
// Fill store with preview content
2522
const items = [
@@ -29,15 +26,15 @@ export default defineNuxtPlugin((nuxt) => {
2926
]
3027

3128
// Set preview meta
32-
window.localStorage.setItem(
33-
`@content:${token}$`,
29+
await contentStorage.setItem(
30+
`${token}$`,
3431
JSON.stringify({
3532
ignoreBuiltContents: (data.files || []).length !== 0
3633
})
3734
)
3835

3936
for (const item of items) {
40-
window.localStorage.setItem(`@content:${token}:${item.parsed._id}`, JSON.stringify(item.parsed))
37+
await contentStorage.setItem(`${token}:${item.parsed._id}`, JSON.stringify(item.parsed))
4138
}
4239
}
4340

0 commit comments

Comments
 (0)