nuxt / content

The file-based CMS for your Nuxt application, powered by Markdown and Vue components.
https://content.nuxt.com
MIT License
3.13k stars 627 forks source link

Unable to query localized content in Nuxt Content with experimental clientDB and no SSR #2846

Open dxlliv opened 1 day ago

dxlliv commented 1 day ago

Environment

Nuxt version: 3.14.159 Nuxt Content version: 2.13.4 SSR: false

Error happens during development and after server side content generation.

Reproduction

https://stackblitz.com/edit/sos-nuxt-content-npcvlj?file=nuxt.config.ts

It works with default language https://sosnuxtcontent-ewna--3000--f565b097.local-credentialless.webcontainer.io/omg/error

but not with secondary languages https://sosnuxtcontent-ewna--3000--f565b097.local-credentialless.webcontainer.io/it/omg/errore

Describe the bug

Hi, I'm experiencing an issue while querying localized content with Nuxt Content in a setup with SSR: false and experimental.clientDB enabled.

Following the suggestion in issue #2062, I enabled clientDB to make Nuxt Content work with static generation and ssr: false. Everything happily worked as expected until I tried filtering content by locale.

I'm on latest versions of Nuxt and Nuxt Content. Here's a code example of how I'm filtering content by locale:

const myItems = ref([]);

await useAsyncData(queryContentKey, async () => {
  const document = await queryContent(queryContentKey).locale(locale.value).findOne()

  myItems.value = document.list
})

With .locale(locale.value) it doesn't retrieve anything, but if I disable the experimental DB client it works again.

Additional context

I'm using clientDB as suggested in issue #2062, because without it, querying content with SSR: false results in a 404 error on the generated content. I'm building an app with Capacitor and need to keep SSR: false; otherwise, the app size increases significantly (200MB with SSR vs. 24MB without).