prisma-examples icon indicating copy to clipboard operation
prisma-examples copied to clipboard

TypeScript + Next.js: Switch from getInitialProps to getStaticProps (SSG)

Open karlhorky opened this issue 4 years ago • 3 comments

Next.js 9.3 introduced static-site generation, moving from getInitialProps to getStaticProps and getServerSideProps.

The typescript/graphql-nextjs example uses getInitialProps, which prevents use of these new APIs in pages.

Is it possible to switch to the new APIs? The following pull request in the Next.js examples did the same switch and can be used as a reference:

https://github.com/vercel/next.js/pull/13742

karlhorky avatar Jul 16 '20 08:07 karlhorky

@ruheni I believe we can close it now 👌

ref: https://github.com/prisma/prisma-examples/pull/3033

koniuszy avatar Aug 08 '21 16:08 koniuszy

@koniuszy am I understanding correctly that #3033 no longer does any server-side / static build-time fetching (eg. which was done previously via getInitialProps)?

I guess if this is the case, it is a slight regression in that it is fetching the data only once React actually renders...?

If this is the case, for an example that uses Next.js to its full potential, my issue #1875 is still valid and should be reopened.

cc @ruheni

karlhorky avatar Aug 08 '21 20:08 karlhorky

@kandros right, since we had the loading condition working I believe it wasn't implemented correctly 🤷‍♂️

I've removed loading conditions and added the server fetching on build time,

the only issue I see is a failing build due to not hosted gql server - probably there is nothing we can do about it, i've added a comment: https://github.com/prisma/prisma-examples/pull/3056/files#diff-1dc6e8f388abb6745bc3f068eb339d4ff2faab2225d5245671c99c37fdb219daR19

koniuszy avatar Aug 09 '21 09:08 koniuszy

@ruheni thanks for #4232 ! 🙌

I've opened #4234 to remove legacyBehavior and simplify the Next.js <Link> component usage.

karlhorky avatar Nov 07 '22 13:11 karlhorky