Next.js Discord

Discord Forum

Dynamic path does not generate HTML even with getStaticProps

Unanswered
Birman posted this in #help-forum
Open in Discord
BirmanOP
Summary

I have some pages being ISR instead of SSG even without revalidate in getStaticProps.

How to force them being SSG and not ISR on build time?

Context

I have a [...path].tsx file that uses getStaticPaths and getStaticProps. When I run yarn build it even shows me the SSG ●

![image](https://github.com/vercel/next.js/assets/13950513/a5ee43a1-e1ea-40e9-b6c8-ce227d70701f)

I realise this might be ISR, but this is the message shown on build:

●  (SSG)      prerendered as static HTML (uses getStaticProps)
   (ISR)      incremental static regeneration (uses revalidate in getStaticProps)


I don't have revalidate anywhere

export const getStaticPaths: GetStaticPaths = async (context) => {
  const cmsPaths = await fetchCmsPaths()
  const locales = context.locales || []

  const paths = cmsPaths
    .filter((path) => path !== "/" && path !== "/404" && path !== "/500")
    .map((path) => locales.map((locale) => ({
        params: { path: path.split("/").filter(Boolean) },
        locale,
      })),
    ).flat()

  return { paths, fallback: "blocking" }
}


export const getStaticProps: GetStaticProps<ContentPageProps> = async (
  context,
) => {
  const segments = context.params?.path as string[]
  const path = segments.map((segment) => `/${segment}`).join("")

  const cmsPage = await fetchCmsPage({ path })

  if (!cmsPage) { 
    return { notFound: true }
  }

  return { props: { cmsPage } }
}


When I visit the .next/server/pages folder, instead of having the pre-built HTML (like my index.html and others), I have just this:

![image](https://github.com/vercel/next.js/assets/13950513/1da75cbb-afd3-4253-86a7-ab147ca97b2f)

The moment I run yarn start and visit one of the pages caught by [...path].tsx file, a HTML magically appears inside the folder.

For very specific project reasons, I need all the HTML to be pre-built and not incrementally generated like it's happening right now.

How can I achieve that?

3 Replies

@Birman **Summary** I have some pages being ISR instead of SSG even without `revalidate` in `getStaticProps`. How to force them being SSG and not ISR on build time? **Context** I have a `[...path].tsx` file that uses `getStaticPaths` and `getStaticProps`. When I run `yarn build` it even shows me the SSG `●` ![image](https://github.com/vercel/next.js/assets/13950513/a5ee43a1-e1ea-40e9-b6c8-ce227d70701f) I realise this might be ISR, but this is the message shown on build: ● (SSG) prerendered as static HTML (uses getStaticProps) (ISR) incremental static regeneration (uses revalidate in getStaticProps) I don't have `revalidate` anywhere tsx export const getStaticPaths: GetStaticPaths = async (context) => { const cmsPaths = await fetchCmsPaths() const locales = context.locales || [] const paths = cmsPaths .filter((path) => path !== "/" && path !== "/404" && path !== "/500") .map((path) => locales.map((locale) => ({ params: { path: path.split("/").filter(Boolean) }, locale, })), ).flat() return { paths, fallback: "blocking" } } tsx export const getStaticProps: GetStaticProps<ContentPageProps> = async ( context, ) => { const segments = context.params?.path as string[] const path = segments.map((segment) => `/${segment}`).join("") const cmsPage = await fetchCmsPage({ path }) if (!cmsPage) { return { notFound: true } } return { props: { cmsPage } } } When I visit the `.next/server/pages` folder, instead of having the pre-built HTML (like my `index.html` and others), I have just this: ![image](https://github.com/vercel/next.js/assets/13950513/1da75cbb-afd3-4253-86a7-ab147ca97b2f) The moment I run `yarn start` and visit one of the pages caught by `[...path].tsx` file, a HTML magically appears inside the folder. For very specific project reasons, I need *all* the HTML to be pre-built and not incrementally generated like it's happening right now. How can I achieve that?
what is your next version? from the build log, it doesn't seem like the pages have been generated
BirmanOP
Latest version. Yep, they weren’t, that’s exactly the question
@Birman Latest version. Yep, they weren’t, that’s exactly the question
could you try something like this and see if the get generated?
//const paths = cmsPaths
//  .filter((path) => path !== "/" && path !== "/404" && path !== "/500")
//  .map((path) => locales.map((locale) => ({
//      params: { path: path.split("/").filter(Boolean) },
//      locale,
//    })),
//  ).flat()
const paths = [
      { params: { path: ["1", "1"] } },
      { params: { path: ["2", "2"] } },
    ]