shuding / nextra

Simple, powerful and flexible site generation framework with everything you love from Next.js.
https://nextra.site
MIT License
11.56k stars 1.25k forks source link

Flexsearch only includes visited pages in dev #2448

Open silas opened 11 months ago

silas commented 11 months ago

Not sure if this is something that can be easily fixed with the current NextraSearchPlugin setup, but it was initially confusing to me that Flexsearch was only including a subset of pages when running it in dev.

You can see this on main by running examples/docs and loading the root page.

If you look at the nextra data file you'll see:

$ cat .next/static/chunks/nextra-data-en-US.json | jq .
{
  "/": {
    "title": "Introduction",
    "data": {
      "": "Nextra is a Next.js based static site generator.It supports Markdown and React components (MDX), automatically\ngenerated sidebar and anchor links,\nfile-system based routing, built-in syntax highlighting, image optimization,\ncustom layouts, i18n, and all the features you love about Next.js.Here's what you will get in 1 minute:"
    }
  }
}

If you then click Getting Started you'll see:

$ cat .next/static/chunks/nextra-data-en-US.json | jq .
{
  "/": {
    "title": "Introduction",
    "data": {
      "": "Nextra is a Next.js based static site generator.It supports Markdown and React components (MDX), automatically\ngenerated sidebar and anchor links,\nfile-system based routing, built-in syntax highlighting, image optimization,\ncustom layouts, i18n, and all the features you love about Next.js.Here's what you will get in 1 minute:"
    }
  },
  "/get-started": {
    "title": "Get Started",
    "data": {
      "quick-start-with-vercel#Quick Start with Vercel": "You can start by creating your own Nextra site and deploying to Vercel by\nclicking the link:Vercel will create the Nextra repository and deploy the site for you with just a\nfew clicks. Once done, every change in the repository will be deployed\nautomatically.",
      ...
    }
  }
}

If you reset the dev server the file is reset.

Do you think it's worth calling this out somewhere in the documentation or maybe updating how this file is generated in dev to include all the data?

dimaMachina commented 11 months ago

A good explanation of why this happens is written here https://github.com/shuding/nextra/issues/2077#issuecomment-1644905328

You probably have noticed this doesn't happen on Development environment, because dev only loads indexes for pages you already visited (that are in the .next/statics/chunk), so it won't load those heavy pages. But, during the build process, it generates these chunks for every page available on your project, thus breaking your page when you focus on Search field.

PR to improve docs is welcome

silas commented 11 months ago

A good explanation of why this happens is written here #2077 (comment)

Thanks for the link!

PR to improve docs is welcome

Yeah, I was trying to find a good place to add a note, but there isn't anywhere obvious. The only place search is really mentioned is in the themes config and I doubt anyone would notice it there.

A page dedicated to search would probably be useful at some point, but I don't really have enough content to justify adding one right now.

I guess I'll just close this issue for now, maybe it's existence and the link provided will be enough for people that go digging.