Skip to content

Commit bc01cde

Browse files
committed
fix: ignore built content in preview mode
1 parent a2e29e7 commit bc01cde

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/runtime/composables/client-db.ts

+6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ export function createDB (storage: Storage) {
2424
// Merge preview items
2525
const previewToken = getPreview()
2626
if (previewToken) {
27+
// Ignore cache content if preview requires it
28+
const previewMeta: any = await storage.getItem(`${previewToken}$`).then(data => data || {})
29+
if (previewMeta.ignoreBuiltContents) {
30+
keys.clear()
31+
}
32+
2733
const previewKeys = await storage.getKeys(`${previewToken}:`)
2834
const previewContents = await Promise.all(previewKeys.map(key => storage.getItem(key) as Promise<ParsedContent>))
2935
for (const pItem of previewContents) {

src/runtime/preview/preview-plugin.ts

+10
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,19 @@ export default defineNuxtPlugin((nuxt) => {
2323

2424
// Fill store with preview content
2525
const items = [
26+
...(data.files || []),
2627
...data.additions,
2728
...data.deletions.map(d => ({ ...d, parsed: { _id: d.path.replace(/\//g, ':'), __deleted: true } }))
2829
]
30+
31+
// Set preview meta
32+
window.localStorage.setItem(
33+
`@content:${token}$`,
34+
JSON.stringify({
35+
ignoreBuiltContents: (data.files || []).length !== 0
36+
})
37+
)
38+
2939
for (const item of items) {
3040
window.localStorage.setItem(`@content:${token}:${item.parsed._id}`, JSON.stringify(item.parsed))
3141
}

0 commit comments

Comments
 (0)