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

db.json is loaded client-side for static site that is not using $content within the client code #837

Closed matthamil closed 3 years ago

matthamil commented 3 years ago

Version

@nuxt/content: 1.12.0 nuxt: 2.14.12

Reproduction Link

No minimal repro (yet)

Steps to reproduce

We recently rebuilt our documentation at Cypress.io to use nuxt and nuxt-content. We are building the site using nuxt generate. We have a page that is requesting the db.json file despite the site being generated with nuxt generate and none of the client code is using $content (this should only be called when building the static site). From what I've read, the db.json should not be loaded unless $content is used client-side.

  1. Go to https://docs.cypress.io

  2. Click on "Plugins" in the top header

  3. The page will not redirect immediately because the db.json file is being fetched.

What is Expected?

The /plugins page does not fetch db.json since the $content API is not being used client-side in this statically generated site.

What is actually happening?

The /plugins page requests the db.json on load, causing a noticeable delay before the user can land on /plugins.

danielroe commented 3 years ago

@matthamil Is it possible to see the code - perhaps an open repo? I notice that this is only loaded for /plugins/* unlike the other pages which suggests that there is something different about this section of the site.

matthamil commented 3 years ago

@danielroe My apologies, I had the code link on my clipboard but I'm dumb and didn't paste it into my original post.

Here is the page that handles /plugins/*.

danielroe commented 3 years ago

@matthamil The issue is that that page wasn't being generated in advance. Check your generate script. It's throwing the following error:

 ERROR  Error generating route "/plugins/plugins/index": Plugin Doc not found

You have links to this non-existent page (and others) throughout, and the crawler is trying and failing to generate that page. Once you've replaced those links - a quick search/replace should do - everything should be copacetic.

A side note: consider using generate.fallback to create your 404.html - see docs.

matthamil commented 3 years ago

Thanks a bunch @danielroe! This helped.

danielroe commented 3 years ago

@matthamil A pleasure 😊