Next.js Discord

Discord Forum

What can cause a static page to get picked up as dynamic?

Answered
Odorous house ant posted this in #help-forum
Open in Discord
Odorous house antOP
I have a page without the "use client" directive because I'm using generateMetadata, however this prevents the page from being prerendered. What can I do to make the page prerender while using next-translate to provide the meta description?
Answered by Ray
need to see the code to know what happen
but you could try making the page static by
export const dynamic = "force-static"
View full answer

20 Replies

Odorous house antOP
I tried to remove the generateMetadata, add the use client directive and then set the description from the component with Head and meta, however it won't show up, I'm guessing because i'm forced to use the metadata API?!
@Ray what do you mean preventing the page from being prerendered?
Odorous house antOP
the build log says that it's a dynamic page:
â–²  Route (app)                              Size     First Load JS
▲  ┌ λ /                                    7.57 kB        89.6 kB
▲  ├ ○ /_not-found                          874 B          82.9 kB
▲  ├ ○ /test                                4.16 kB        86.2 kB
â–²  â”” â—‹ /w                                   14 kB           110 kB
â–²  + First Load JS shared by all            82 kB
▲  ├ chunks/702-b90a9b6911af03f1.js       26.7 kB
▲  ├ chunks/fd9d1056-ccb7338427d7537f.js  53.3 kB
▲  ├ chunks/main-app-ee1f6df6f87bbe93.js  217 B
â–²  â”” chunks/webpack-6dd0546617f0832a.js   1.84 kB
â–²  
â–²  â—‹  (Static)   prerendered as static content
▲  λ  (Dynamic)  server-rendered on demand using Node.js
oh so you want static page, right?
Odorous house antOP
yes
generateMetadata doesn't prevent the page being static generated
however, if you have used cookies, headers or searchParams in the page or generateMetadata it will become a dynamic page
do you use one of these on that page?
Odorous house antOP
i only use these:
import useTranslation from "next-translate/useTranslation"
import styles from "./page.module.scss"
import Link from "next/link";
maybe the Link using it? because i use useTranslation in the /w route and it's prerendered
need to see the code to know what happen
but you could try making the page static by
export const dynamic = "force-static"
Answer
Odorous house antOP
thanks that did work
nice
Odorous house antOP
btw this is the code:
import useTranslation from "next-translate/useTranslation"
import styles from "./page.module.scss"
import Link from "next/link";

export default function Page() {
    const {t} = useTranslation("home");
    return <div className={styles.page}>
        <div className={styles.head}>
            <h1>{t("title")}</h1>
            <p>{t("title_sub")}</p>
            <Link href={"/w"}>{t("create_room_btn")}</Link>
        </div>
        <h2>{t("features")}</h2>
        <ul>
            <li>{t("f0")}</li>
            <li>{t("f1")}</li>
            <li>{t("f2")}</li>
            <li>{t("f3")}</li>
            <li>{t("f4")}</li>
            <li>{t("f5")}</li>
        </ul>
        <h2>{t("p2p_title")}</h2>
        <p>{t("p2p_p0")}</p>
        <p>{t("p2p_p1")}</p>
        <p>{t("p2p_p2")}</p>
        <p>{t("p2p_p3")}</p>
        <p>{t("using_bm")}</p>
        <Link href={"/test?n=25"}>{t("performance_btn")}</Link>
        <h2>{t("using_title")}</h2>
        <ol>
            <li>{t("u_p0")}</li>
            <li>{t("u_p1")}</li>
            <li>{t("u_p2")}</li>
            <li>{t("u_p3")}</li>
            <li>{t("u_p4")}</li>
        </ol>
    </div>
}

export const dynamic = "force-static"

export function generateMetadata() {
    const {t} = useTranslation("home")
    return {
        description: t("desc")
    }
}
how do you change language with next-translate? I haven't used it before
if it use searchParams, that will make the page being dynamic
Odorous house antOP
i only used the path based detection so /w is by default en and /hu/w would be hungarian
so when prerendering it creates pages for all locales defined in the config
ah ok, not sure what made the page opt out caching there then