Next.js Discord

Discord Forum

SSG stops working when switching to remotely hosted CMS

Answered
Giant panda posted this in #help-forum
Open in Discord
Giant pandaOP
I have Next.js fetch its pages and blog posts from Strapi CMS with output: 'standalone'. When I point my build to locally hosted Strapi it creates a standalone directory that has SSG working - I can shut down my Strapi and it will still display pages. But when I point my build to remotely hosted Strapi it still generates a standalone directory with all necessary files, but if I stop access to remote Strapi and run the server it will not serve static html files and instead switch to full SSR and try to fetch data from remote Strapi.

Things I have tested:
Removed all cache in both the .next directory and the .next/standalone directory
Look if the generated html files are present in the standalone/.next/server/app directory - they are in both cases
Compare the two standalone directories (local Strapi vs remote Strapi) - seems the only thing that is different is the chunks' file hash, everything else seems to be pretty much the same

Any idea why the server does not serve the statically generated html files?
Answered by Giant panda
The problem was that right now export const dynamicParams = false breaks SSG if the fetches you do have set the {next: { revalidate: false/0; }} option. So what I had to do was remove that revalidate option and SSG started working correctly. I found this in a github issue - https://github.com/vercel/next.js/issues/52765#issuecomment-1918147128
View full answer

12 Replies

Giant pandaOP
Bump
Giant pandaOP
Bump
Giant pandaOP
Bump
Toyger
if it's ssg, it should generate ready files at build time, did you try to update to last nextjs, are you usgin generateStaticParams for static data?
what code you have there? maybe something wrong with it.
it's hard to say anything without some minimal reproducible example.
Giant pandaOP
@Toyger I'm using generateStaticParams, I will be able to show full page.tsx code on Tuesday. Files are also generated successfully in both cases, the only difference is when Next.js is connected to a remotely hosted Strapi the SSG doesn't seem to work, almost like it cannot see the generated static html files.
Giant pandaOP
This is the page.tsx code that sits in `app/[slug]/ :
What could maybe cause a problem is the dynamic imports that are happening in the BlockManager component - I've made BlockManager dynamically search for components based on the name of the component coming from Strapi to prevent the manual importing of every component, here is that code as well:
This is all server components, again, not sure how this will affect SSG when switching to different address of Strapi
Giant pandaOP
I tried removing the dynamic imports to check if that fixes anything, but Next.js still switches to SSR when getting the page data from remotely hosted Strapi
Giant pandaOP
@Toyger that does not work for me as I also need to have redirects and SSR pages, but I found the solution
Giant pandaOP
The problem was that right now export const dynamicParams = false breaks SSG if the fetches you do have set the {next: { revalidate: false/0; }} option. So what I had to do was remove that revalidate option and SSG started working correctly. I found this in a github issue - https://github.com/vercel/next.js/issues/52765#issuecomment-1918147128
Answer