Next.js Discord

Discord Forum

Site gets prerendered during build although using dynamicio

Unanswered
Giant Chinchilla posted this in #help-forum
Open in Discord
Giant ChinchillaOP
I am using the experimental feature dynamicio.
I experience that sites are prerendered although I do not use "use cache" on top of the file there. IMO this should be the equivalent to "force-dynamic", because otherwise I have no way to disable prerendering for pages with dynamicio.

Do I do something wrong or is it a misconception from my side? How do I stop nextjs to render something during build then?

Thanks! 🙂

12 Replies

Next.js will always try to generate your pages at built time, as static, when they have no reason not to be.

If you’re using dynamicIO and you’re not making use of any dynamic API and you’re not marking anything with “use cache” then next.js will see if the page can be statically generated, because why not?

I believe that’s always been the case with Next.js even before all the new additions to the framework. And seems they’ll continue to, since they bet on Partial Pre-Prerendering to become the default.
I believe the way to mark something as “dynamic” is by literally wrapping it in <Suspense>, anything outside of the boundary is not considered dynamic by default, I feel the pain too:(
Giant ChinchillaOP
Dear Luis, thanks for your explanations. Unfortunately, although I am using Suspense in my Root-Layout, it still prerenders everything. 😕
Do you have “use cache” in the pages/funtions/component used within your pages?

If there’s nothing left to be dynamic even if you have everything wrapped in <Suspense> the app will end up being pre-rendered.

Also, do you have PPR enabled? This also will try to pre-render as much as possible
Giant ChinchillaOP
I only have set dynamicio and do not use "use cache" in all pages except in some function calls. Thus, it shouldn't pretender right? Before using dynamicio I could disable it by using const dynamic = "force-dynamic" 🤔
Giant ChinchillaOP
I have nothing set up for ppr in the config. The only thing I did was to put Suspense in the Root Layout.
I’m somewhat unfamiliar with “use cache” I just know the theory but what is different in your use case if you remove the Suspense in the root layout?
Giant ChinchillaOP
Sorry for my late response. I have tested this now. The page without "use cache" is still prerendered when I remove Suspense from my RootLayout.
@Giant Chinchilla Sorry for my late response. I have tested this now. The page without "use cache" is still prerendered when I remove Suspense from my RootLayout.
Apparently Next.js tries to optimize your app by keeping pages static as long as they don’t require to be dynamic
Giant ChinchillaOP
The weird thing is that it also prerenders pages that are refering to functions using "fetch" calls. I am retrieving text placeholders via an api and I dont want them to be included into the docker image build. Therefore I do not want to have these pages prerendered at build time. 😦