r/reactjs • • Mar 29 '21

News Next.js 10.1 – 3x Faster Refresh, Image Improvements, Apple Silicon Support

https://nextjs.org/blog/next-10-1
573 Upvotes

103 comments sorted by

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!

30

u/UtterlyMagenta Mar 29 '21

this is awesome, thanks for all your great work! it's amazing you've managed to cut your installation size and number of dependencies by over 50%. 🎉 also it’s interesting to hear about your new profiling tool.

one question:

“Custom 500 Page” — wasn't this already possible with pages/_error.js or what is the difference?

28

u/lrobinson2011 Mar 29 '21

Thank you so much! Correct, you can also handle errors with _error.js. The difference is pages/500.js is completely static, instead of having to hit your server.

8

u/nikola1970 Mar 29 '21 edited Mar 29 '21

Good job man. Thanks, love NextJS!

11

u/lrobinson2011 Mar 29 '21

Thank you! I can only take a small bit of credit, most of this work is from the many amazing contributors and core team 🙏

7

u/diamond_monkey666 Mar 29 '21

lrobinson2011

hey Lee amazing work once again

2 questions -

  1. will the shopify next commerce demo code be available as a repo?

  2. I have used lquip loader in the past - would this work with the updated next/image

thanks

7

u/lrobinson2011 Mar 29 '21
  1. Yes, the code is open-source here: https://github.com/vercel/commerce

  2. Currently, blur-up placeholders for next/image aren't supported natively - but we're working on it!

7

u/acemarke Mar 29 '21 edited Mar 29 '21

Probably a bad place to file a pseudo bug report, but...

I just tried updating a Next project from 10.0 to 10.1, and I'm seeing weird behavior.

Running next dev results in the Next process spawning an infinitely swapping series of child processes, which pegs my CPU. Granted, locked-down corporate machine, but 10.0 did not do this.

Some of the child processes appear to be labeled jest-worker or something similar. Not sure if test-related, or if Next is just using that lib to do worker pool behavior.

This happens every time I re-launch next dev consistently. (Currently nuking node_modules to see if that makes a difference.)

Anyone else seeing anything similar or have an idea what might be going on?

edit

after bisecting my way through a dozen Next versions, including a bunch of 10.1 pre-alphas, I've isolated the issue to starting in 10.0.10-canary.1, which upgraded jest-worker, and filed a new issue to report that:

https://github.com/vercel/next.js/issues/23519

7

u/lrobinson2011 Mar 29 '21

https://github.com/vercel/next.js/issues/23519

We will look into this - thank you for reporting!

3

u/straightouttaireland Mar 29 '21

Is there any genuine reason to go with create-react-app instead of NextJS? I don't need SSR or SEO.

5

u/lrobinson2011 Mar 29 '21

If you're heavily bought into React Router, some folks prefer that over the current routing support with next/router for single-page apps (SPAs).

2

u/straightouttaireland Mar 29 '21

Yea I mean it's the only router I've used so can't exactly say it's better or worse than anything else. I guess I'm trying to decide if it's worth learning the NextJs way of doing things and extra config vs just sticking with what I know. Project dependent I guess.

3

u/lrobinson2011 Mar 29 '21

The majority of what you know from Create React App will transfer to Next.js :) If you have 30 minutes, read through http://nextjs.org/learn and check it out!

→ More replies (1)
→ More replies (1)

2

u/[deleted] Mar 29 '21

How do I make a vercel app so i can oauth to it and deploy via the api?

3

u/lrobinson2011 Mar 29 '21

It sounds like you're looking for our Integrations API!

https://vercel.com/docs/integrations

1

u/[deleted] Mar 29 '21

I got authentication errors last time i tried to set it up and just went with netlify instead

5

u/lrobinson2011 Mar 29 '21

Oh wait, are you trying to add "log in via Vercel" OAuth to your application? That's not something that Vercel currently supports. I'd recommend using Next Auth to support OAuth login from whatever provider you need.

https://next-auth.js.org/

2

u/nilsepils94 Mar 29 '21

Hey Lee, so awesome to see you're so actively helping the community!

We're currently seeing 20 minute build times, since we're building 25.000 pages on deploy. Each page has to do its own api request, even though some of the endpoints don't change (mixing colors, sizes and i18n strings for each product). Is this something you see Next.js optimizing for in the near future?

8

u/lrobinson2011 Mar 29 '21
  1. Are you building pages statically? Have you explored Incremental Static Regeneration?

  2. Yes! We're working on layouts support, which means you could share a layout for a set of pages and make a single API call (e.g. getStaticProps) for that layout.

1

u/nilsepils94 Mar 29 '21
  1. We have, and we're actively looking into supporting that. But currently it might take 10s to server render each page, so that's a horrible experience for the first one to hit a page (which will happen often since we have many, which invalidated them often). Decreasing that is definitely our main line of thought right now though.

  2. That sounds awesome!

10

u/lrobinson2011 Mar 29 '21

In the case of ISR, even if it takes 10s to "server-render", it's happening in the background. So your users never see that - they see stale content first, then the cache gets updated with the new static content. Does that explanation help?

→ More replies (1)

1

u/dbbk Mar 29 '21

We're currently seeing 20 minute build times, since we're building 25.000 pages on deploy.

Why would you do this?

4

u/nilsepils94 Mar 29 '21

We're selling 150x products, in 2-8 colors in 20 countries speaking 8 different languages

SSR isn't cutting it for us (external data is very slow), so we have to go SSG route

6

u/dbbk Mar 29 '21

Sounds like you should just be doing SSR and stick a CDN in front of it. It takes 5 minutes to set up Cloudflare and it's free.

→ More replies (1)

2

u/SaraTheAntiZ Mar 29 '21

Hi lee

I just have one question; what is the limit for the number of ssg pages?

Let's say I have these "/products/[productId]" pages and I want them to be statically generated? how many of these pages I can generate before facing the issues that u/nilsepils94 is facing??

2

u/lrobinson2011 Mar 29 '21

There is no limit when using incremental generation.

Example and more details: https://static-tweet.vercel.app/

4

u/SaraTheAntiZ Mar 29 '21

Thanks lee, I actually learned something.

Would you also explain this part of data fetching document:

You should not use fetch( ) to call an API route in getStaticProps. Instead, directly import the logic used inside your API route. You may need to slightly refactor your code for this approach.

Why can't we do this? Does this have any performance benefit?

5

u/lrobinson2011 Mar 29 '21

You can do that, but it's not recommended specifically for performance. Since API Routes run on the server anyways, there's no point in making an extra network hop from the getStaticProps API to your API route. Instead, you can write whatever code would be inside your API route directly in getStaticProps or getServerSideProps. If you absolutely need to, it will still work if you call the API route, though.

2

u/[deleted] Mar 30 '21

Thank you for all your hard work and congratulations on the release!

I use nextJS at work and I love how seamless it is to move a data fetch from the client to the server and choosing which parts should be statically generated.

In my last project we needed support for CSP and I understand this is something you’re working on. Do you have an update for us on this?

2

u/lrobinson2011 Mar 30 '21

Could you share more on what you're looking for? Is there a related issue I can read more into?

→ More replies (1)

6

u/castelli-dev Mar 29 '21

I’m loving Next.js, truly awesome! Thanks!

1

u/Epailes Mar 29 '21

How does image optimization work if it's a static site exported to say aws s3 for hosting? As there's no place for cache or processing to be performed on the server side.

1

u/lrobinson2011 Mar 29 '21

Correct - you would need to use an external provider like Cloudinary (which would do the optimization) in combination with your static site. This is mentioned in the blog post via the loader prop. You can bring whatever optimization service you prefer, or you the WASM optimization out of the box when running next start.

2

u/HetRadicaleBoven Mar 30 '21

Are there any plans to support applying the optimisations at build-time and support SSG using that? I presume that can significantly impact build time if you have lots of images, but if it's optional it sounds like a valid trade-off (build speed vs. runtime speed) a developer could wish to make?

2

u/m-sterspace Mar 30 '21 edited Mar 30 '21

See this discussion here: https://github.com/vercel/next.js/discussions/19065

Long and short of it is that they say they're going to add build time image optimization, but won't commit to a time frame, so I'm guessing this is an item that's detailed and sitting in their backlog, but had yet to be prioritized into the sprint planning.

There's a community project called next-optimized-images that I believe can be configured to do what you want and optimize images at build time, though I haven't personally tried it.

→ More replies (1)

1

u/[deleted] Mar 30 '21 edited Mar 30 '21

I just started learning NextJS after teaching myself React in the winter! One question for you Lee:

Are there any other next tutorials/courses you recommend doing after completing this one? https://nextjs.org/learn

2

u/lrobinson2011 Mar 30 '21

You can take https://react2025.com which is free :)

2

u/[deleted] Mar 30 '21

Looks great! I'll definitely check it out. Thank you :)

1

u/[deleted] Mar 30 '21

Wes Bos has Advanced React course where he uses NextJS to build the front end. Might be worth looking into. https://advancedreact.com/

→ More replies (3)

0

u/[deleted] Mar 30 '21

[deleted]

2

u/m-sterspace Mar 30 '21

Maximilian's Academind courses are the best. They're how I cut my teeth and what I recommend for everyone. He's a really great teacher.

→ More replies (3)

1

u/[deleted] Mar 30 '21

I will be building my next app using Next. From my limited experience it seems great. I've used CRA up until now and had issues where we needed to SSR one page but not the others. From my understanding you can opt-in/out of SSR with Next but by default it's SSR. This is brilliant. I also like the idea of dynamic routes, SEO support and preview links.

Question; is there concern/excitement over Rust front ends rapidly improving? How will Next compete (obviously won't be for a hood while yet!)?

1

u/mrchief_2000 Apr 01 '21

u/lrobinson2011 can you share details about the profiling tool?

0

u/nodir3d Mar 29 '21

Any way to deploy projects that use oracledb as a be database in vercel?

1

u/lrobinson2011 Mar 29 '21

I don't know a lot about Oracle Database, but Next.js doesn't care which database you use. It's un-opinionated in that regard. Vercel can connect to any database as well (note Vercel is not your database but hosting, deploying, and collaboration).

→ More replies (3)

0

u/[deleted] Mar 29 '21

[deleted]

5

u/lrobinson2011 Mar 29 '21

I'm biased but from a pure SSG functionality standpoint, Next.js can achieve the same result as Gatsby (and more). I prefer it, but I'd say try both out and see what you think!

9

u/iSDestiny Mar 30 '21

The developer experience of Next.js is a lot better IMO, very easy to get into.

3

u/m-sterspace Mar 30 '21

Imho I vastly prefer Next.js as I really don't like Gatsby's whole hyper opinionated forced GraphQL business.

Next.js operates much more logically in my opinion. They just let you run arbitrary node.js code at build time that you can use for whatever you want, including fetching data and generating pages based on it.

No need to force every single data source into GraphQL form, just fetch from a REST API like you normally would.

Only downside I see over Gatsby is that out of the box, Next.js does not support build time image optimization like Gatsby does, though there is a third party library to add it.

0

u/[deleted] Mar 29 '21

[deleted]

2

u/lrobinson2011 Mar 29 '21

It is not yet. We will share more when it is on by default!

1

u/[deleted] Mar 30 '21

[removed] — view removed comment

2

u/lrobinson2011 Mar 30 '21

Short: make it as easy as possible to create a performant, scalable, globally distributed React application with best practices included.

→ More replies (1)

15

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

u/lrobinson2011 Mar 30 '21

Thank you so much!

2

u/p0mpeii_ Mar 30 '21

Amazing, thanks for community request based development! Can't wait to try out the new image placement features.

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

u/[deleted] 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.

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.

→ More replies (1)

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

u/[deleted] 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

u/Imaginary-Apartment Mar 29 '21

Awesome update from an awesome team!

4

u/[deleted] Mar 30 '21

Really loving the work you guys are putting here!

1

u/[deleted] 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?

https://github.com/vercel/next.js/discussions/23498

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/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?