#Understanding static site generation in NextJS 15 (App router)

1 messages · Page 1 of 1 (latest)

real basalt
#

EDIT: Just created a project from scratch with the same code and it's working as expected, I'll pay a look on what differences (probably some libraries) are making my project to work in a different way

I'm doing a migration of some of my static pages to the new App Router and I'm facing some 'issues', I don't fully get how the static pages works on the new router, for example one of my pages is connected to Contentful and I followed the tutorials to achieve SSG, in the build the page is labeled as "(Static) prerendered as static content" but logging my "getData" function the page is still doing a call on the first load of the page, after the first load the page seems to be cached and I don't get the log again.

I also did a very simple page in order to test and I get the same behavior, is this normal for my scenario? Should I verify if SSG is working in a different way (not with the logs)?

This is the test page that I created to test, the getData function is called at build time generating the html in the .nexjs folder but also in the first load of the page:

`async function getData() {
console.log("[TESTPAGE] getData"); // This is called on build time and on the first load of the page
const aboutPageData = await fetch(
"http://jsonplaceholder.typicode.com/posts",
{ cache: "force-cache" },
).then((response) => response.json());
return aboutPageData;
}

export default async function listPage() {
const data = await getData();
if (!data) {
return { notFound: true };
} else {
return (
<div>
{data.map((post: any) => (
<div key={post.id}>
<h2>{post.title}</h2>
<p>{post.body}</p>
</div>
))}
</div>
);
}
}`

Any comment will be highly appreciated, thanks in advance!

solemn daggerBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

vital iris
#

Have you tried forcing the static generation?

export const dynamic = “force-static”

real basalt
#

Yes, @vital iris , I forgot to add that in my message, I get the same behavior adding "force-static"

real basalt
#

Just created a project from scratch with the same code and it's working as expected, I'll pay a look on what differences (probably some libraries) are making my project to work in a different way

vital iris
#

Is the Next.js version the same in both projects? I ask because when talking about caching behavior is important, the defaults have changed

hybrid rune
#

also worth mentioning whether you have dynamicIO or some other experimental features enabled in one project but not in another

#

async stuff works different ways with dynamicIO enabled

real basalt
#

I was looking in the differences between my apps and I just found that the project that I'm migrating is still working with React 18, I think that could be the problem, I'll update that and check again, thanks guys!

real basalt
#

Well, I updated to React 19 and my only difference is that in my project I'm working with the app and pages router at the same time, I did a cleanup of the layout component in case something there was working in a weird way but even with a simple layout every page calls the data on the first load even being generated as static pages, I'm not sure what else can I try