kit icon indicating copy to clipboard operation
kit copied to clipboard

Configure error reporting when routes were marked as prerenderable but were not prerendered

Open yakanet opened this issue 1 year ago • 5 comments

Describe the problem

Currently when prerendering a website, if some pages are not prerendered, the following message is thrown during build time :

The following routes were marked as prerenderable, but were not prerendered because they were not found while crawling your app ...

Sometime this is an expected behaviour, for some pages, if there is no data, they should not be prerendered.

As a simple example, a blog website. Following the list / detail page pattern, when there is no content, we couldn't prerender the website until there is at least 1 content, (as the detail page is marked as prerendable but has not been prerendered).

Currently this error is not configurable, there is no options to be able to warn or silent this one.

Describe the proposed solution

Following the example of handleEntryGeneratorMismatch, would be great to have an option handleNotPrerenderedRoutes to be able to configure the error reporting

Alternatives considered

No response

Importance

nice to have

Additional Information

No response

yakanet avatar Jan 21 '24 10:01 yakanet

As a simple example, a blog website. Following the list / detail page pattern, when there is no content, we couldn't prerender the website until there is at least 1 content, (as the detail page is marked as prerendable but has not been prerendered).

If there is no content to prerender (yet) then the page should not be set to be prerendered. Can you expand on why the page which has no content yet needs to be prerendered?

teemingc avatar Oct 10 '24 07:10 teemingc

My use case is: the website is consuming data from a headless CMS, and the whole website is prerendered with the static adapter.

Some data are time limited (different data every days), and the website is built every days to fetch the latest data.

For some days, I don't have any data in the headless CMS (this is a normal behaviour), so the pipeline in charge of building the website is failing. Currently, I'm patching Sveltekit to avoid throw an error during the build phase.

Here a more practical example for this use case : A website is displaying news, so we have a /+page.svelte to display the list of news and a /[id_news]/+page.svelte to display the news detail. Those news has a short publication time range (couple of days) and for some days, there is no news to display. So there is no problem for building /+page.svelte but the build error happen when building /[id_news]/+page.svelte.

I understand it might be a weird use case, but if we could opt-in in the configuration to avoid the build error (same kind of configuration just like other flags as handleHttpError or handleMissingId), that could solve this use case.

yakanet avatar Oct 10 '24 08:10 yakanet

Have you tried adding the fallback option to the adapter config and setting the prerender for the dynamic parameter route to prerender = 'auto'? I think this is a good compromise because if there is no prerendered content available, it will still show the fallback page, and if there is prerendered content, those pages will be prerendered.

teemingc avatar Oct 10 '24 09:10 teemingc

Hi @eltigerchino,

and thank you for your answer.

The website use adapter-static, it needs to be fully prerendered. Unfortunately, neither fallback option or prerender=auto is suitable for this fully prerendered requirement.

Here is a simple reproduction example: https://www.sveltelab.dev/zqvb17sqqgl1dm3

  • When there is data in +page.server.ts the command npm run build will generate every pages
  • When there is no data in +page.server.ts the command npm run build will fail with the following error :
Error: The following routes were marked as prerenderable, but were not prerendered because they were not found while crawling your app:
  - /[slug]

The issue is due to this line : https://github.com/sveltejs/kit/blob/main/packages/kit/src/core/postbuild/prerender.js#L511

Most of the time this is an expected error, but in my scenario I would like to swallow this error (or be able to adjust the error level - WARN for example). It would be great if we could have a similar configuration as handleMissingId configuration

yakanet avatar Oct 11 '24 12:10 yakanet

Hi @yakanet , I wasn't able to reproduce the issue with the reproduction you've linked. Could you create another minimal reproduction?

teemingc avatar Oct 14 '24 03:10 teemingc

I can reproduce this when commenting in the array clear.

It's an interesting use case, as there's nothing pointing to your entry point, but as you show it can be expected sometimes.

dummdidumm avatar Jan 10 '25 16:01 dummdidumm

I would love to see a solution for this. I can explain my use-case. I have a horse racing website, where I every night fetch the latest startlists for upcoming racedays and then prerender the content. However, sometimes there are not any startlists ready to fetch, which means my build fails and my website doesn't update. This also means that old startlists are on the site unless I do some manual work to fix that.

Edit I have found a workaround where I add some entries with dummy slugs to the svelte.config entries: ['*', '/startlister/galop/0', '/startlister/trav/0'] And then have a 307 redirect in +page.ts if the slugs are dummy.

bechii avatar Feb 03 '25 08:02 bechii