Expected behavior for dynamic routes when hitting invalid urls #89140
Replies: 4 comments
-
|
Add References: |
Beta Was this translation helpful? Give feedback.
-
Expected Behavior for Invalid Dynamic Route URLsWhen a user hits an invalid URL for a dynamic route (e.g., How to Handle Invalid Dynamic ParametersOption 1: Use
|
| Scenario | Behavior |
|---|---|
| No validation | Page renders with invalid param |
Using notFound() |
Shows not-found.tsx with 404 status |
dynamicParams = false |
Auto-404 for unlisted params |
Docs Reference
Beta Was this translation helpful? Give feedback.
-
|
I appreciate the input from you both @abhishekmardiya and @aaneloy, however I think you may have missed some context in my original question, here are the requirements and then the expected behavior in tldr format:
I would then expect no static files would be generated for the 404 routes, however this does not seem to be the case. |
Beta Was this translation helpful? Give feedback.
-
|
For this you need to define a cacheHandler - https://nextjs.org/docs/app/api-reference/config/next-config-js/incrementalCacheHandlerPath - then you handle the ISR cache yourself. You can give it a go with an in-memory implementation first, and then save to disk - I haven't played all that much with this config but it should work (I managed to generate one though). |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Setup / context
npx create-next-appgenerateStaticParams:.next/server/appdir, all static page resources are present as expected:foohas been pre-compiled so that works like a charm.bar, the otherallowedPagethis generates static files as expected given it should return a valid response fromfetchPage.However when entering a url that does not exist, i.e.
/baz, files for this non-existent page are created in the.next/server/appdirectory.generateStaticParamsand then testing, non of the static files related to the invalid routes are generated. But equally, all pages are now dynamically created on visit and not statically generated at build time (not ideal).Thoughts / question
I would expect that any urls resulting in a 404 response would not generate related static files and instead just use the
not-found/error-pagefiles.My primary concern is around the potential for a bad actor to flood a site with requests generating page files and inflating the disk usage on the server. I get that the alternative to having these files generated is that whatever API is providing the context for these pages existence is hit more frequently; say if people keep hitting
/baztechnically next knows this page doesn't exist due to the static files, but just trying to understand the exact intent here.Please let me know if I am missing something or if this is expected behaviour.
Cheers.
Additional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions