-
Notifications
You must be signed in to change notification settings - Fork 27.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update examples with getInitialProps to SSG #11014
Comments
This new feature doesn't seem to work with saga and redux now |
Updated a bunch of examples in this PR: #11136 |
Thanks for the clarification. @lfades Sorry for the misleading. I meant the original example only doing a But your answer makes me think I might misunderstand something here. So, sorry for the noob question, let's say in a typical SaaS case, there is a page, and for each client, the page needs different data. My question is: In this case, isn't because Thanks 😄 |
TL;DR: Never. If a page uses data based on the user, you should do client side rendering with loading states, the typical case is for the page to be pretty much the same, but the data is different, so you output static HTML for the layout, and then make a request and show the data once it's ready. This is usually how pages like Twitter, vercel.com and more do it. It's better to show the client something very fast, and then make a request and let them wait with content (even if it's a loding spinner), that to make then wait in a blank page for a serverless function to return the initial HTML. With SSG and without I hope that answers your question, if it's still not clear, go to our Discussions tab, there are multiple conversations about this 👍 |
Thanks so much for the clarification!
I will check the discussion tab! |
Related to #11014 The authentication method has been replaced with an improved version of the passport example.
…13898) Related to [11014](vercel#11014)
@lfades |
Related to [11014](vercel#11014) Upgraded all the packages from package.json, removed the saga-wrapper package since it is totally outdated to today's use. I have refactored the whole example using the new API of the next-redux-wrapper package, using their new support of "getStaticProps". All of the class components were converted to functional, using the new redux hooks API. If you want me to change anything or you are not satisfied with any given change, I'm open to suggestions.
Related to [11014](vercel#11014) 1. I have changed the component from class to functional. 2. I have removed the getInitialProps and used getStaticProps instead. 3. I have removed the redundant connect to redux @ the index page, due to the fact that now we can dispatch the action with the required hook. If you want me to change anything or you are not satisfied with any given change, I'm open to suggestions.
Related to [11014](vercel#11014) First and most important, removed the getInitialProps and used getStaticProps. Then, I refactored Counter, DataList and Examples components. I have refactored them from class-based components to functional. Also in each component the redux implementation was refactored using the new hooks API, which resulted in ~40% less code. If you want me to change anything or you are not satisfied with any given change, I'm open to suggestions.
Related to [11014](vercel#11014) 1. Moved the reducer into the store and created new store file 2. The example was using a server that was no longer available, now it uses JSON placeholder instead. 3. Moved from getInitialProps to getStaticProps 4. Refactored all the classes to functional components, using the new redux hooks API. 5. Upgraded all the packages and using custom redux wrapper instead of next-redux-wrapper, which I have removed from the example. 6. Upgraded all the other packages. Please, let me know if I should change anything.
[11014](vercel#11014) Removed getInitialProps from _app
Related to [11014](vercel#11014). Removed getInitialProps in favor of getStaticProps and getServerSideProps. Refactored one of the components from class to functional. Removed redundant imports. Removed React.FC/FunctionComponent. Added two build files to gitignore. Let me know if you want something to be changed.
Related to [11014](vercel#11014)
Related to vercel#11014 The setup is very similar to the one used for Apollo examples. @Joezo I've removed the demo example that you added to the readme (vercel#6482) as it will be outdated after this PR is merged.
…el#13849) Related to vercel#11014 The authentication method has been replaced with an improved version of the passport example.
…13898) Related to [11014](vercel#11014)
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
With the release of Next.js 9.3 we are empowering all Next.js applications to take advantage of the JAMStack, before this, around half of our examples were using
getInitialProps
for data fetching in pages, and even though we are not removing it any time soon, it's not ideal for most applications. You can read more about this here.Around half of our examples (110+) are using
getInitialProps
. and in most of those examples it can be replaced with getStaticProps to take advantage of SSG.Any updates to take advantage of SSG in current examples using
getInitialProps
are deeply welcome and will be merged ASAPPRs for New examples using
getStaticProps
/getStaticPaths
and removal of current examples that are very outdated or not worth upgrading are also very welcome.Here are some of the examples currently using
getInitialProps
:https://github.com/zeit/next.js/tree/canary/examples/amp-firsthttps://github.com/zeit/next.js/tree/canary/examples/analyze-bundleshttps://github.com/zeit/next.js/tree/canary/examples/api-routeshttps://github.com/zeit/next.js/tree/canary/examples/auth0
https://github.com/zeit/next.js/tree/canary/examples/blog-starterhttps://github.com/zeit/next.js/tree/canary/examples/custom-server-expresshttps://github.com/zeit/next.js/tree/canary/examples/data-fetchhttps://github.com/zeit/next.js/tree/canary/examples/ssr-cachinghttps://github.com/zeit/next.js/tree/canary/examples/using-routerTo find more examples, do a global search inside our examples for
getInitialProps
, and with the exception ofpages/_document.js
any other result is one that we don't want!If an example can only work with
getInitialProps
, updating it to use getServerSideProps is also welcome.Update: Please create a PR per example update, this will speed up the review and merge process 🙏
The text was updated successfully, but these errors were encountered: