[Bug]: app-dir, API routes with `dynamic` = `error` are still rendered at runtime
Fox32 opened this issue · 1 comments
Summary
I'm using the new app-dir router. I want to use dynamic
= error
for my API route that have access to data and build time, but not later during execution.
A link to a reproduction repository
https://github.com/Fox32/nextjs-dynamic
Expected Result
I would expect that the state of the route created during build time is served, or otherwise an error is triggered. In no situation it should try to reevaluated the page.
Actual Result
I see that a .next/server/app/[filename].body
and .next/server/app/[filename].meta
file is generated during build that contain the right state, but these aren't served during runtime. Instead the route is reevaluated, which fails as my dependecies are not available at runtime.
Steps to reproduce
I have two deployments:
- Vercel
- Netlify
For Vercel, both routes return newly the same date/time, but more important, the value stays the same. For Netlify, the page seems to be cached (or even using the static value from build time) and the API is reevaluates every time.
As a workaround, I added this code the the beginning of my route, but I don't think this scales very well if I have a lot of routes 😉
if (process.env.AWS_REGION) {
const body = await readFile('./.next/server/app/[filename].body', 'utf-8');
const metadata = JSON.parse(
await readFile('./.next/server/app/[filename].meta', 'utf-8')
);
return new Response(body, metadata);
}
Next Runtime version
4.39.4
Is your issue related to the app
directory?
- Yes, I am using the
app
directory
More information about your build
- I am building using the CLI
- I am building using file-based configuration (
netlify.toml
)
What OS are you using?
None
Your netlify.toml file
`netlify.toml`
# Paste content of your `netlify.toml` file here
Your public/_redirects file
`_redirects`
# Paste content of your `_redirects` file here
Your next.config.js
file
`next.config.js`
# Paste content of your `next.config.js` file here. Check there is no private info in there.
Builds logs (or link to your logs)
Build logs
# Paste logs here
Function logs
Function logs
# Paste logs here
.next JSON files
generated .next JSON files
# Paste file contents here. Please check there isn't any private info in them
# You can either build locally, or download the deploy from Netlify by clicking the arrow next to the deploy time.
Hi @Fox32
The team at Netlify have now released the new v5
Next.js runtime which has support for both pages and app router, on-demand and time-based revalidation, automatic fine-grained cache control, and automatic image optimization using Netlify's image CDN.
You can find the documentation and additional information on the new runtime here: Next.js on Netlify
The v4
runtime is now in the maintenance support phase with no new features being added. Occasional bug fixes and security patches will be applied when needed.
Thanks!