Next.js Discord

Discord Forum

SSG Dynamic Route not Behaving as such

Answered
Barbary Lion posted this in #help-forum
Open in Discord
Barbary LionOP
Hello, I'm hoping someone can help me with a very simple problem.

I have a very simple site. I have a CMS where I am gathering block posts within a dynamic route and surfacing these with generateStaticParams from within the app router.

Here is my generateStaticParams and exported configs:

And the default page component:
<image1>

The build of my site in Vercel seems sensible:
<image2>

Which seems to be understood properly by nextjs when I inspect the components of the site:
<image3>

So great, my dynamic routes are being generated as SSG routes.

Now, when I actually go to the route in the deployment URL, my default Post function is being re-rendered! I know this as the console logs are showing up:
<image4>

Am I not understanding how SSG works and is this the normal behaviour, or is this abnormal?
Answered by Barbary Lion
FYU going from 14.0.3 to 14.1.0 seemed to do the trick... Can't see anything in the release notes that hint at a fix. Logs included in page routes are no longer appearing in production
View full answer

39 Replies

Barbary LionOP
Bump! I know there is a simple answer to this one. I just can't figure out this behaviour
Barbary LionOP
I have attempted to force static site generation with no luck. Heres my generateStaticParams config:

// raise an error when path is not part of the static list
export const dynamicParams = false
export const dynamic = 'force-static'

export async function generateStaticParams() {
  console.log('!!! GENERATE STATIC PARAMS START !!!')
  const postsResponse = await databaseClient.queries.postConnection()
  const edges = postsResponse.data.postConnection.edges || []
  console.log('!!! GENERATE STATIC PARAMS END !!!')

  return edges.map((edge) => ({
    slug: edge?.node?._sys.filename ?? '',
  }))
}
Barbary LionOP
I've scoured the issues, and I think this is exactly what I am experiencing:
Barbary LionOP
Yup! The issue is definetely the use of the Link component - just tested in production. Does anyone have any thoughts as to why this would be causing SSG pages to regenerate?
Milkfish
I had a look at your code and couldn't find anything that stuck out at me... My understanding is the _rsc is to return the JSON code instead of the html... but I would have assumed that this would load a static generated JSON file as well
Are you using anything on the page that would overwrite dynamicParams / ssg?
e.g. headers function, cookie function, etc
Barbary LionOP
Hi @Milkfish thanks for your help on this.

There's nothing in the page that I am aware off that is overwriting the dynamicParams SSG, to my knowledge. I am using a CMS (Tina) to gather content, then surfacing it at build time to generate the SSG pages. The flow looks like this:

generateStaticParams
- gather all slugs via graphql query

Post
- for the provided slug, gather the post content via graphql and render it
Here is the page.tsx that sits within blog/[slug]/
I see no use of cookies from the helper functions. This is just a simple post renderer
And FWIW, I am using hte app router.
Milkfish
Honestly out of ideas... I think it probably is a bug (or feature???), because your next build output was showing it had been detected as a static site - and only rerendered when it uses next/link
Barbary LionOP
Yup! it's bizzarre...
I really think this is happening because of the Link component. I can remove every link component apart from 1 - a button component I have built.

This button component is used to navigate to the post. And it is now the only route that does a forced rerender. The navigation to /blog now just correctly serves the SSG. Adding prefetch={false} to the link component does not help...
Milkfish
You could temporarily use a <a> tag instead of link to prevent RSC - but kind of defeats the purpose of layouts, and all the other app router goodies
Barbary LionOP
Yes exactly
For now, as I am building a very simple static site, I can stomach those tradeoffs
Milkfish
Would be interested to know if you could create a minimal reproduction, or perhaps there's something else in your code causing the issue
Barbary LionOP
Yup good idea.
I will see if I can create a dummy route and see if I can reproduce the problem
Barbary LionOP
I actually think there might be something else going on...
I think the fact that search params are being added are triggering a rerender
Is there any way in my route config to just ignore search params, as far as the route is concerned?
Milkfish
search params are added to the link, or used in the page function?
Barbary LionOP
Added to the link. No page searching functionality has been included
If I force the use of an a tag I get rid of the _rsc param. But there persists a nxtpslug param. That still manages to trigger a rerender
I though the purpose of these exports was to prevent a rerender on addition of params:// raise an error when path is not part of the static list
export const dynamicParams = false
export const dynamic = 'force-static'
I though the purpose of these exports was to prevent a rerender on addition of params:

export const dynamicParams = false
export const dynamic = 'force-static'
Here is what the GET request looks like, which is triggering a rerender:
/blog/Post-With-All-the-Bells-and-Whistles?nxtPslug=Post-With-All-the-Bells-and-Whistle
Milkfish
Crazy. Definitely seems like a bug
You're testing this on a production build right?
Barbary LionOP
Latest tests are on a preview branch. But this whole issue is occuring on my main prod branch. NODE_ENV is set to production for both regardless
Milkfish
just thought i'd check! Only other thing I could think of
Barbary LionOP
Yeah it's a good suggestion
I am at a loss. Seems like something so simple. According to the docs this setup should just work.
Milkfish
Bug report I reckon
@Milkfish Bug report I reckon
Barbary LionOP
Yup, thanks for all your help
Barbary LionOP
FYU going from 14.0.3 to 14.1.0 seemed to do the trick... Can't see anything in the release notes that hint at a fix. Logs included in page routes are no longer appearing in production
Answer