Next.js Discord

Discord Forum

Next 14 : catch-all static route is filling up the disk space on 404

Unanswered
Western paper wasp posted this in #help-forum
Open in Discord
Western paper waspOP
Our application has a catch-all static route which tries to fetch data from the CMS in order te render the content for a given slug.
There are bots on the production environment which try to run scripts (for example wordpress hacks) on it.
All these requests result in generating 3 files in the .next/server folder. This is slowly filling up the disk-space and there doesn't seem to be a documented way to opt-out on caching results for 404 pages. When no content is found, the notFound() function is being used to render a custom 404 page.

The options provided by the route segment configuration doesn't seem to be flexible enough to change: We do want regular pages to be statically cached. Just not all the spammed routes which result in a notFound anyways.

Anyone knows a way around this or a good solution?

1 Reply

Western paper waspOP
In case you are also buming against this issue:

After a lot of research : It turns out this is "just how Full Route caching works" as the moment:
https://nextjs.org/docs/app/building-your-application/caching#full-route-cache

There are ways to opt-out on this:

* Marking it all as dynamic -> which is a no-go for us.
* Marking it as dynamicParams=false -> which is also a no-go for us.

All other ways to make this page dynamic at request time (unsafe_noStore, dynamic functions, fetch with no-cache) result in:
"Page changed from static to dynamic at runtime"
https://nextjs.org/docs/messages/app-static-to-dynamic-error
Telling this is not supported in nextjs - but is pretty much exactly what we want to achieve here.

Meaning the only documented way around this is ... check my notes again ... redeploy the whole app .... 🙂

I senserely hope this gets better in the future.
If anyone knows another way - feel free to share.