r/reactjs • u/lrobinson2011 • Mar 29 '21
News Next.js 10.1 – 3x Faster Refresh, Image Improvements, Apple Silicon Support
https://nextjs.org/blog/next-10-115
u/PCslayeng Mar 30 '21 edited Mar 30 '21
I've been using Next on and off for two years now. The changelogs have been such a pleasure to read, and I've been very happy with all of the quality of life improvements lately. Reducing bundle size and dependencies, increasing performance, fast refresh, and a bunch of other huge improvements without needing to change anything in my projects. Outstanding work, kudos to your team!!
4
2
u/p0mpeii_ Mar 30 '21
Amazing, thanks for community request based development! Can't wait to try out the new image placement features.
1
25
u/m-sterspace Mar 29 '21
I've been using Next.js as a Static Site Generator instead of Gatsby (too opinionated in my humble opinion 😋) and I have to say that I've been loving it.
Coming from Create React App there's been a little bit more to configure and set up to get it working completely smoothly, but I'm impressed by what a big difference it makes in terms of page load time and performance. Overall it's been awesome.
1
u/straightouttaireland Mar 29 '21
I'm still in the create-react-app camp as I don't need SSR or SEO. Just a standard SPA.
9
u/itsthekeming Mar 30 '21
If you’re comfortable in SPA land, check out Vite. I find it much faster than CRA.
2
u/straightouttaireland Mar 30 '21
I still think Vite is a bit new to use in production. I know there's a ReactJS version but I feel it's more geared and better supported when using Vue.
7
u/sole-it Mar 30 '21
I have worked on a few projects using Next.js (SSG) this year. In hindsight, two of these projects would be better sticking with CRA. Both are interactive-heavy and have complex in-app state processes. And one app was limited by Next's routing system.
But these two perform well and it's a good learning experience for me to know the pros and cons of each tools.
1
u/straightouttaireland Mar 30 '21
Yea. I think it would be good to try out NextJS but on the surface for my project I don't need SSR, SEO or routing so I feel NextJS would be overkill.
1
u/m-sterspace Mar 30 '21
Out of curiosity what do you mean by this?
Both are interactive-heavy and have complex in-app state processes. And one app was limited by Next's routing system.
I can understand being limited by Next/router as Reach Router is a little opinionated, but why would interactive heavy or complex in-app state matter?
...There's nothing different about a Next.js site vs a CRA site in those regards as far as I know.
0
Mar 30 '21
[deleted]
1
u/HetRadicaleBoven Mar 30 '21
If you use Static Site Generation, you're technically generating a number of SPA's (one for each page). These are SPA's in the sense that they emulate server-side routing using client-side routing after loading.
However, in a traditional SPA, you set that single-page to catch all requests to a URL pattern, allowing you to support completely custom URLs like
yourdomain.com/product/[productId]. If you try to do that with a purely statically rendered NextJS site, you'll have to pick one of the pages to fall back to, which will lead to the prerendering mismatching the actual content for some routes.2
u/m-sterspace Mar 30 '21 edited Mar 30 '21
However, in a traditional SPA, you set that single-page to catch all requests to a URL pattern, allowing you to support completely custom URLs like yourdomain.com/product/[productId]. If you try to do that with a purely statically rendered NextJS site, you'll have to pick one of the pages to fall back to, which will lead to the prerendering mismatching the actual content for some routes.
I mean, this is just a an issue with how you configure your hosting provider. You can host a SPA raw on something like Blob Storage, and when you navigate to index.html the whole site will work, but navigating to any sub urls directly via their address will fail as those files don't actually exist.
To setup a hosting service properly for a traditional SPA, you need to configure your hosting provider to redirect any and all requests back to serving up index.html. In something like Azure Static Web App, you do this by configuring your routes.json file and add a rule with a wildcard to redirect all url requests back to the same file.
However, with a statically rendered SPA like Next.js, you might not even need redirect rules with your hosting provider if all your pages are statically generated. Or more likely, you'll need to configure the redirect rules, but you'll just need to match the routing for your next project. i.e. serve up the statically rendered page for pages that have been, and otherwise fallback to the appropriate dynamic page.
If you're using something like the Azure Static Web App service, then it's just a matter of configuring your routes.json file with rules that match your exportPathMap file.
→ More replies (10)1
u/Gadjjet Mar 30 '21
How does global state work then (not redux)? Something like context or reactive variables that are currently available to all the routes in CRA. We are making a massive dynamic website with complex state. I work in medical research and we have a lot of complex forms, tables, data graphs e.t.c. We are trying to decide if we need to switch off CRA to something else before we get too far down the line.
→ More replies (1)3
u/HetRadicaleBoven Mar 30 '21
After you navigate to one of Next.js's statically-generated pages, any further page transitions will be done client-side (which is why I think of them as a bunch of SPA's), so all client-side state should be preserved between page transitions just like when using CRA.
That said, if you're currently using CRA and don't experience any problems, I don't see any reason to migrate.
1
u/straightouttaireland Mar 30 '21
You can but on the surface for my project I don't need SSR, SEO or routing so I feel NextJS would be overkill.
1
u/m-sterspace Mar 30 '21 edited Mar 30 '21
You can. Next.js can do absolutely everything CRA can do and more.
I would use CRA if I need to mock something up quickly, but if it's a longer term project and I have an hour or so to configure everything correctly, then now that I know how to use it, I would always start with Next.js.
11
Mar 29 '21
If you want a beer, it's on me u/lrobinson2011 you guys have knocked it out of the park with Next!
5
4
1
Mar 30 '21
Bundle size are increasing when using, so i don't really understand where does reduction coming from
future: {
webpack5: true,
},1
u/lrobinson2011 Mar 30 '21
Hey, could you share more details here with a reproduction on your bundle size increase?
3
u/green_03 Mar 30 '21
I’ve been using Next.ja since v5 and have recently started refreshing a personal site with the new version. Many thanks to everyone for their hard and beyond excellent work! These things DO make the web a better place!
1
u/dillonerhardt Mar 30 '21
Love the continued focus on improving the developer experience. Nice work!
1
u/Direct96 Mar 30 '21
u/lrobinson2011 When user integration with shopify will be done ? :)
https://github.com/vercel/commerce/blob/master/framework/shopify/api/customers/login.ts
1
u/Migom6 Mar 30 '21
What's the best way to produce logs in request/ route level in next js without using a custom next js router?
160
u/lrobinson2011 Mar 29 '21
Lee from Vercel here, happy to answer any questions about Next.js!
One interesting note not mentioned in the blog post. We've created new performance profiling tooling which will run on each commit into the Next.js repo. This tracks metrics like initial build times, fast refresh times, traces through the system, and more. We used this tooling to test large Next.js applications (our own as well as some Vercel customers) to measure Fast Refresh improvements. Excited for the future of Next.js!