blomqma / next-rest-framework

Type-safe, self-documenting APIs for Next.js
https://next-rest-framework.vercel.app
Other
134 stars 18 forks source link

Need for "force-dynamic" #167

Closed markedwards closed 3 months ago

markedwards commented 3 months ago

I find that I have to add export const dynamic = 'force-dynamic'; boilerplate everywhere I use next-rest-framework. Is it possible to alleviate this? Could the library use unstable_noStore() internally, for instance?

blomqma commented 3 months ago

Thanks, I can confirm that with app router when using the default nodejs runtime, the force-dynamic option is needed for the docs endpoint (docsRoute) because it reads the request headers directly from the original request object, but for the other routes defined with route this shouldn't be needed.

I have created a fix for this in v6.0.1 that reads the request headers from a cloned request object in the app router docs endpoint so explicitly using the force-dynamic caching strategy should no longer be needed.

markedwards commented 3 months ago

Thanks, the issue I had previously when not declaring "force-dynamic" on endpoints seems to no longer be reproducible. However, I do see this warning at build time, when I omit the declarations:

TypeError: Cannot read properties of undefined (reading 'pathname')

Oddly it is only triggered by one of the endpoints, and it goes away if I set export const dynamic = 'force-dynamic'; there.