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

[document-driven] Support fetching on SPA fallback #1654

Open Lexpeartha opened 2 years ago

Lexpeartha commented 2 years ago

Environment

Nuxt project info:


Reproduction

This exact branch: https://github.com/Lexpeartha/portfolio/tree/revert-to-dd

Describe the bug

If you go to page that doesn't exist (and therefore uses DocumentDrivenNotFound.vue), it displays navigation without any actual links as it can be seen here. On any other page things work fine. I've even made to sure to explicitly enable DD in the corresponding not found component, but still the same thing.

Additional context

No response

Logs

No response

atinux commented 2 years ago

Nice found @Lexpeartha

I can confirm the bug also applies to my Content Wind template: https://content-wind.nuxt.space/404

I suspect the bug may comr from https://github.com/nuxt/content/blob/main/src/runtime/plugins/documentDriven.ts#L211

Will investigate next week, but happy to get any help if you have some time, you can test the document driven mode using yarn dev document-driven

atinux commented 2 years ago

Alright I found the bug, since you are using nuxt generate (me too), your page is loaded as SPA fallback (see the page source), so the navigation object is empty.

This is more instead a feature request to support client-side fallback, cc @farnabaz

Lexpeartha commented 2 years ago

@Atinux did you switch to SSR? Opening the error page from your template seems to have a navigation now

Lexpeartha commented 2 years ago

Also when I remove /404 from prerendered routes, it still shows blank

atinux commented 2 years ago

Interesting, I think you can make it work for client fallback by using:

export default defineNuxtConfig({
  content: {
    experimental: {
       clientDB: true
    }
  }
})
Lexpeartha commented 2 years ago

It's still empty

atinux commented 1 year ago

Seems your branch does not exist, did you solve your bug?

Lexpeartha commented 1 year ago

Seems your branch does not exist, did you solve your bug?

No, just merged it into main 😅 It can still be found there

Lexpeartha commented 1 year ago

I played around with it and came across something weird @Atinux, which seems to fixes this in Lexpeartha/portfolio#3

this config doesn't work with SPA fallback and content module

  nitro: {
    prerender: {
      crawlLinks: true,
      routes: [
        '/',
        '/404.html',
        '/project/404',
        '/sitemap.xml'
      ]
    }
  },

However, after adding this:

  generate: {
    routes: ['/', '/work', '/404']
  },

My /404 route seems to have navigation all of the sudden

Not really sure what makes the difference, but wasn't /404.html in nitro.prerender.routes supposed to be a special case that is an equivalent of /404 in generate.routes?

Lexpeartha commented 1 year ago

@farnabaz @Atinux I would be more than happy to try and make a PR for this, could you help me with an overview of what to start with/what needs to be done?

atinux commented 1 year ago

Sorry for the late answer @Lexpeartha

If you try to go to /405 on your website, does it work?

Lexpeartha commented 1 year ago

You can take a look here. Basically how I set it up is any not recognized route is rendering the same as prerendered /404