Next.js Discord

Discord Forum

"no-cache" but for db connections

Answered
Yellow-breasted Bunting posted this in #help-forum
Open in Discord
Yellow-breasted BuntingOP
Hey all, I just realised a lot of my pages in the app router have been marked as ISR, even though I haven't set anything up. I think this is because I'm using a db connection rather than fetch to gather my data at build time. Is there a way to make these pages just standard static pages? Or do I need to wait for unstable_cache to become stable?
https://nextjs.org/docs/app/building-your-application/caching#unstable_cache
Answered by aardani
you should update to 13.5
View full answer

31 Replies

Yellow-breasted BuntingOP
Sure!
nice name btw 😎
no like in the build log
Yellow-breasted BuntingOP
ohh
in the console
Yellow-breasted BuntingOP
this?
and which route do you want it to be static?
Yellow-breasted BuntingOP
they should all be static except the api
static as in statically rendered at run time
all routes are static by default and the use of dynamic features such as headers() and etc can make it turn into SSR
the routes denoted with lambda means that the route is dynamically comptued at runtime, sometimes known as SSR
so to force it to run at static, you need to do all or some of the following
1. make sure you're not using dynamic function like headers() or dynamic routes. (Dynamic routes are dynamically computed at runtime unless you generate the paths)
2. export const dynamic = 'force-static' or 'error'
Yellow-breasted BuntingOP
Heres one of my pages as an example:

const CalculatorPage = async () => {
  const prices = await getPrices();

  return (
    <Wrapper>
      {prices.A}
    </Wrapper>
  )
}
I'll try export the dynamic variable thanks!
I can't know what causes it to opt into dynamic rendering with just that code...
Yellow-breasted BuntingOP
Inside getPrices is something like:
const getPrices = async () => {
  const data = await db.select().from(prices);
  if (!data) {
    throw new Error("No metal prices");
  }
  return { prices };
}
ok thats safe
assuming that its not using headers() in select() or from()
so probably wrapper
Yellow-breasted BuntingOP
Wrapper is just tailwind stuff
I'll give the dynamic export a shot
start with your root layout. since the staticity of a route is determined as a whole not per segment, if the root layout is set to dynamic, then the rest of the child route will also be dynamically computed
so app/layout.tsx
Yellow-breasted BuntingOP
Ah that makes sense sure
Yellow-breasted BuntingOP
Using server actions on a page currently disables static generation for that page 💀
you should update to 13.5
Answer
server action works on SSG in the new version
Yellow-breasted BuntingOP
Heck yeah thank you for your help!