nuxt / content

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

hot reloading data in server mode #2241

Open johan-Rm opened 1 year ago

johan-Rm commented 1 year ago

I would like to do hot reloading of data using a watcher in the same way as we can do it with a classic API.

With the small piece of code below (// Example with classic API) when I use a classic API I get the hot reload of the data but unfortunately at the moment it is not possible to do that with the "*.md".

Do you think this improvement is possible?

watch(timeIntervalBeforeDataCallback, async (newValue, oldValue) => {

    // Example with queryContent()
    // const response = await useAsyncData('data', () => queryContent(`/data/1}`).findOne())
    // data.value = response.data.value

    // Example with regular API
    const response = await $fetch('https://my-api.com/api/data/1').catch((error) => error.data)
    data.value = response

}, { immediate: true })
farnabaz commented 1 year ago

What is the purpose of this watch? Are you trying to fetch newly edited content in dev mode?

Otherwise, it won't work, because contents in production are read-only. Contents did parse at the build time and on production only built contents will load.

johan-Rm commented 1 year ago

The goal is the hot reloading of data in production mode, it works with a classic API (with nuxt start) but not with the ".json" or ".md" files present in content/ folder.

I really like markdown files but i have to keep working without nuxt-content right now because hot reloading data is so cool :)

Is this improvement planned in the roadmap?

Read-only mode is suitable for static generation and server mode could work the same as development mode?