Diego Benetti
Diego Benetti

Reputation: 107

NextJS server side rendering

I'm building an app using NextJS and its server side rendering feature.

If I understood it correctly, to take advantage of it all we need to do is exporting an async function called getServerSideProps in the component we want to server side render.

Curious thing is I noticed my components were being server side rendered even without exporting getServerSideProps function.

Is there any other thing (other than getServerSideProps) that can cause a component to be server side rendered?

Thanks in advance

Additional information:

the directories are like this:

Also, this ViewportContext.tsx relies in the window variable to determine if the client is mobile or desktop.

NextJs version is 13.0.5

Right now, for every request the console.log()s I placed in the components are displayed in the terminal, meaning that there is some server render (I guess) running.

Upvotes: 1

Views: 1123

Answers (2)

matthiasgiger
matthiasgiger

Reputation: 1256

NextJS will always render on the server (and hydrate again on the client). However, without dynamic data from getServerSideProps it can already be rendered during the build and then cached. With getServerSideProps the page will be rendered anew with the up-to-date data for every request by a user. In this case the page will be rendered in a Serverless function.

Upvotes: 0

OneQ
OneQ

Reputation: 1487

In NextJS as you can see here, the default behaviour is Static Generation : https://nextjs.org/docs/basic-features/pages#static-generation-without-data

In version 13 : https://beta.nextjs.org/docs/rendering/static-and-dynamic-rendering

Upvotes: 0

Related Questions