Will export const dynamic = 'force-static' still fetch fresh data during Next Build?
Unanswered
North Pacific hake posted this in #help-forum
North Pacific hakeOP
I wish to replicate the old behaviour of "getStaticProps" using the new app router for a single page. That is, I want the page to be statically generated at build time, and re-built with fresh data the next time I trigger a build. Currently, with Next's data cache, triggering a build will bring in stale data for that page.
Will
accomplish this? I still want the page to be statically re-generated with fresh data when the next build is triggered.
Will
export const dynamic = 'force-static' accomplish this? I still want the page to be statically re-generated with fresh data when the next build is triggered.
14 Replies
The default for every page is to be static... Unless you revalidate it or use a function that forced dynamic (headers), it is going to be static - and this still builds in the built time
@riský The default for every page is to be static... Unless you revalidate it or use a function that forced dynamic (headers), it is going to be static - and this still builds in the built time
North Pacific hakeOP
I understand that but with getStaticProps I can pre-render the page at build time AND not worry about fetching stale data at build time. I want this behaviour with the app router but can’t seem to make it work without making the page dynamic or revalidate on an interval or (god forbid) manually implement some sort of trigger in the backend to invalidate the cache when the front end builds. Are these my only options?
Data Cache is persisted between builds
try using node-fetch to disable Next's fetch caching behavior entirely
@aardani try using node-fetch to disable Next's fetch caching behavior entirely
i mean wouldn't it be better to use
export const fetchCache = 'force-no-store' on root layout?i havent tried it sorry, but using node-fetch works in my experience
North Pacific hakeOP
I don’t want to disable caching site wide. All other pages (except this one) are on dynamic routes and generateStaticParams works the way I expect at build time.
well you can still use alfon's suggestion about fetch cache and disable it for a simgle fetch req:
fetch('https://...', { cache: 'no-store' })https://nextjs.org/docs/app/building-your-application/caching#opting-out-1@riský well you can still use alfon's suggestion about fetch cache and disable it for a simgle fetch req: `fetch('https://...', { cache: 'no-store' })`https://nextjs.org/docs/app/building-your-application/caching#opting-out-1
im just afraid this would turn his Route into Dynamic SSR route not SSG
as with my previous experience, not sure if its still that way
oh i see, i was under the impression that they were 2 diferent caches... but i can see the possibility of it breaking
North Pacific hakeOP
Yes, it becomes dynamic ssr. They seem to have taken away a capability that existed in the page router with this particular use case. I'm frustrated.
try using node-fetch then @North Pacific hake
Philippine Crocodile
I find myself in a similar situation. I use Strapi CMS, and whenever I make changes, it initiates the build and deploys of my Next (static) project. However, I've noticed that the data doesn't update unless I set a revalidate policy in seconds for my fetch request.
Is there a more effective way to manage this type of situation?
Is there a more effective way to manage this type of situation?