Skip to content

Commit

Permalink
fix: ignore built content in preview mode
Browse files Browse the repository at this point in the history
  • Loading branch information
farnabaz committed Oct 6, 2022
1 parent a2e29e7 commit bc01cde
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/runtime/composables/client-db.ts
Expand Up @@ -24,6 +24,12 @@ export function createDB (storage: Storage) {
// Merge preview items
const previewToken = getPreview()
if (previewToken) {
// Ignore cache content if preview requires it
const previewMeta: any = await storage.getItem(`${previewToken}$`).then(data => data || {})
if (previewMeta.ignoreBuiltContents) {
keys.clear()
}

const previewKeys = await storage.getKeys(`${previewToken}:`)
const previewContents = await Promise.all(previewKeys.map(key => storage.getItem(key) as Promise<ParsedContent>))
for (const pItem of previewContents) {
Expand Down
10 changes: 10 additions & 0 deletions src/runtime/preview/preview-plugin.ts
Expand Up @@ -23,9 +23,19 @@ export default defineNuxtPlugin((nuxt) => {

// Fill store with preview content
const items = [
...(data.files || []),
...data.additions,
...data.deletions.map(d => ({ ...d, parsed: { _id: d.path.replace(/\//g, ':'), __deleted: true } }))
]

// Set preview meta
window.localStorage.setItem(
`@content:${token}$`,
JSON.stringify({
ignoreBuiltContents: (data.files || []).length !== 0
})
)

for (const item of items) {
window.localStorage.setItem(`@content:${token}:${item.parsed._id}`, JSON.stringify(item.parsed))
}
Expand Down

0 comments on commit bc01cde

Please sign in to comment.