chantastic.fm

121: Tim Neutkens on Next.js 10

Episode 121 · December 3, 2020 · 01:02:46

Hosted by chantastic · With Tim Neutkens

Sponsored by Honeybadger and Infinite Red

Download MP3 · Jump to transcript

Featuring

Discord

Join the discussion Discord 🎉🎊🥳

Listeners of React Podcast are chatting on Discord!
Join us Friday at 10am CT for a friendly chat thru the latest episode.
It's fun, interactive and all are welcome!

Links

Sponsors

Honeybadger

When errors make it all the way to a user, you want Honeybadger monitoring at your back. honeybadger.io

Infinite Red

In over your head with a React or React Native app? Infinite Red can help. They're React Native core contributors who've been designing, building and shipping apps for over 10 years. reactpodcast.infinite.red

Transcript

[00:00:00] Michael Chan: This is React Podcast. I'm Chintastic, and I'm inviting you to my one-time-a-year event, React Holiday. It's 25 React-related tips delivered right to your inbox. This year's focus is non-React skills that support great React development: JavaScript, JSX, and even HTML. Sign up for this newsletter at react.holiday. That's react.holiday, and get 25 lessons right to your inbox. Now cue the music. Tim Nuetkens joins us to talk about the new tech in Next.js 10. At this year's Next.js Conf, they announced killer new performance features that came from their partnerships with Google and the React core team. In this chat, Tim shares what that means for users and developers alike. This episode is supported by Honeybadger and Infinite Red. Let's be honest, you ship code with errors. Don't worry, I do too. Oftentimes errors get caught by automated or QA tests, but sometimes they don't. When you push code with errors and those errors make it all the way to the user, you want Honeybadger at your back. Honeybadger monitors and sends alerts in real time, providing the context you need to quickly identify and eradicate errors in your day-to-day deployments. Honeybadger gives you DevOps superpowers by combining error monitoring, uptime monitoring, and cron monitoring in a single, easy-to-use platform. And Honeybadger doesn't just have your back. They also alert you when external services fall over or background jobs start to fail. Get 30% off of Honeybadger for 6 months by mentioning React Podcast at signup. There's no credit card required. Just visit- Honeybadger. Honeybadger.io. At honeybadger.io, you'll find the story of Starr, Josh, and Ben, the bootstrappers behind Honeybadger, and why self-funding means your interests are always number one. Check them out at honeybadger.io. Infinite Red is your go-to resource as a React and React Native developer. They know these frameworks inside and out. It doesn't matter if your company is huge, medium, or small. Infinite Red can help you design, build, and ship quality apps. They've been doing it for over 10 years, and listeners of this show Absolutely love having them as a friendly expert resource. Infinite Red will give you $750 when you start or refer a new project. Get expert React and React Native help at reactpodcast.infinite.red. Tim, welcome back to React Podcast.

[00:02:43] Tim Neutkens: Hey, thanks for having me.

[00:02:44] Michael Chan: I'm excited to get you back on the show. Um, I think It's- I think last time we talked, it was maybe um Next 9 was kind of the release. I I don't remember exactly how long ago. But it's been a minute. And you all have done some some amazing stuff. Um do you remember uh kind of like what what it was that we covered last time?

[00:03:04] Tim Neutkens: So, last time, I think we talked about automatic static optimization. So, that was something we introduced in Next.js 9. Um and a bunch of other features. And I think that was like 1.5 years ago or so. Uh, so like a lot has happened since then. Yeah.

[00:03:20] Michael Chan: Totally. A lot, yeah, a lot happens in, uh, in 18 months for sure. Um, yeah, and I think like AMP was a pretty big, um, headline feature at the time, um, because you had just started working with Google, um, on, you know, with their teams to kind of like figure out what it was that they wanted to see in this, you know, static site generation and how you could better optimize for the things that you know, a company like Google cares about.

[00:03:43] Tim Neutkens: Yeah, exactly. So, um, like in in Next.js 9.2, I believe we- actually in Next.js 8 point something, we we released AMP support, uh, which was like our first collaboration with the uh Google AMP team, uh, to basically make it easier to author AMP pages, uh, which is this format that, um, It uses web components. It's basically like a component framework where you can import uh certain components into uh AMP pages and then uh use those instead of like creating your own manually. Um and then like later on, we we introduced a collaboration with the Google Chrome team, which is uh completely separate from the AMP team, uh where they uh basically are helping us improve performance for all Next.js applications, uh but also like just build on top of like existing web standards and like bring um like optimizations that were previously not possible because like you didn't have the end-to-end solution for it, basically.

[00:04:51] Michael Chan: I love that. I, you know, it's kind of funny that you mentioned that the group Google Chrome and the Google Google AMP team are like two totally different collaborations. Um I think, you know, Oftentimes we have a mental model of, you know, like all- even though these companies are huge, that they kind of work together on everything. But no, it's like two different teams. And so like, as you've been doing this, it sounds like you've been working with two different sets of people, but like under the same organization.

[00:05:18] Tim Neutkens: Yeah, exactly. So like large companies like Google and Facebook, etc., they all have like so many teams in there that Like, they they could be like not working together, or they could be under the same org and then like working together, but like side by side, right? Um, so like there's a lot of intersection between like AMP and Chrome, for example, because like they uh try to optimize performance in certain ways, right? Um, but then there's also like many teams inside of Chrome itself that are like completely focused on other things, right? Like people building Lighthouse and people building uh Chrome DevTools and and all that, so.

[00:05:56] Michael Chan: Yeah.

[00:05:57] Tim Neutkens: And those are like different people from the people that we're working with, for example. Um, but they're all in touch, of course, 'cause like they they're in the same org, yeah.

[00:06:06] Michael Chan: Interesting. It must be fun to kind of like go through the, uh kind of have reasons to kind of go through the different parts of the org chart as you're developing uh Next. I wanted to ask, I mean, so you had just put on a huge conference, um and so you have Next.js Conf and uh there was a lot going on there, a lot of really cool releases. And so before we talk about um the things that are specific to Next 10, uh I just wanted to get a sense of, you know, what putting on that conference was like. Uh were you surprised by anything? What's the Next community look like these days?

[00:06:41] Tim Neutkens: Yeah, definitely. So, uh 2 weeks ago, uh 27th of October, uh 2020, we, uh we had a conference, Next.js Conf, and, uh we had 70,000 signups, uh with about 35,000 people attending. Um, just like 50%. Um, and yeah, we we announced, uh we had a keynote and in the keynote we uh announced Next.js 10. Uh but not just Next.js 10, we also announced Next.js Analytics, uh which is a new service that allows you to measure performance. And we introduced uh Next.js Commerce, which helps you get started building an e-commerce site really quickly. Uh, so it's like a starter for building out your own e-commerce store on top of Next.js. And that was created together with the the BigCommerce team, which is a um software as a service uh e-commerce provider.

[00:07:37] Michael Chan: Nice, nice. And I I think it's really interesting. This was a really fun event to watch, like from my perspective, because it seems like you are building, like, so you have the Next platform and it is like pretty stable. Uh, in, you know, spoiler alert, Next.js 10 doesn't have any breaking changes. Uh, it has a lot of new features, but not breaking changes. And so, it's cool to see that you've kind of started doing more to augment Next. Um, so, whether that be Next uh Next Commerce, et cetera, et cetera. Uh, tell me a little bit about how you see Next kind of in these these coming years and what it will look like to develop on Next?

[00:08:18] Tim Neutkens: Yeah, so, uh, like, first of all, like you were saying, like, there were no breaking changes in Next.js 10. Um, like, the, the thing that we're basically trying to do is, like, make it as easy as possible for people to upgrade to the latest version, be that a, like, patch version, minor version, or a major version even. Uh, so even if, like, a major version, like, would deprecate something, like, we would always Like give you another way to um like do the same thing, but probably like more efficiently or in a different way that is is better for like bundle size or for uh other metrics. Um so really committed to making sure that like you're not getting uh like a really like awful upgrade path where uh like you spent months upgrading and then like figuring out like how all the new things work and all that. So it's pretty stable, uh like since uh we released Next.js 9. We actually spent a lot of time, like in the first 2 years or so, Next is now 4 years old, like we released many major versions, mostly to upgrade like underlying dependencies that had major version upgrades, like Babel and Webpack and all that. Um, but we, like the the core API is still like very true to what the first version had. Like you still have the pages directory, you still have filesystem routing, um, you still have the Link component, you still have Next Head, uh, and all that. Uh, so like really, like we're continuously like augmenting incrementally towards a uh better way of doing things, or like integrating a way that people are already doing things um in their own application, but making it easier for them to uh like not focus on those specific bits when they start like either a new application or like they can cut down some code in uh their current application, basically.

[00:10:13] Michael Chan: I love that. Now, you touched on something that I really like to talk about on this show and have very few opportunities to talk about is um versioning. And I think it's really interesting because you're on version 10 right now, um but there's no breaking changes. And you you mentioned a little bit about how you think about versioning and how if you have an underlying um dependency change, uh you'll make a breaking change for that. Um are there other things that tie into kind of major versions for something- for an API that you own that doesn't have breaking changes?

[00:10:46] Tim Neutkens: Yeah, for sure. So, uh, it could be that like you- like an example of that is like Next allows you to configure your custom webpack config, right? So, if you want to add in like custom loaders or custom plugins, like that all is possible. Uh, but if you do so, you lose out on us being able to know that your application is going to work if you upgrade. Gotcha. Because like you make some edits and like maybe we change something in our like the built-in config and then like things could potentially break, right? Because you're making some edits in like an object that like we don't know about. Um and then like those could be like, okay, we know that like the majority of Next.js apps is fine to upgrade. Uh but if you're like going to upgrade and you have custom plugins, like webpack plugins, Um, that could break, like we're still going to do a major, right? So, like, for example, like Webpack 4, a Next.js app on Webpack 4 that doesn't have custom webpack config is going to run fine on Webpack 5 as well. Uh, because like we made sure that it's completely backwards compatible. Uh, even with like breaking changes in Webpack itself, like we uh, like covered those as well as like a backwards compatibility layer. But then like we don't know for sure if it's going to work for all Next.js apps. So like we don't release it as a minor or a like patch version, right? And then we also have many like integration tests. So like pretty much all our tests, like 99% or so, are integration tests that run against like Next.js apps being booted in uh continuous integration. And actually like the tests are written against like a browser instance that is just like accessing pages in the same way that you would do it as a developer.

[00:12:33] Michael Chan: Interesting. Interesting. I like this because I think, you know, it stands in pretty interesting contrast to the way React versions- you know, it's like we've been on, you know, the version 16 of React for about 3 years. And I think that's one of the reasons I ask is because it's really interesting to see- I think different people take different strategies for how they want those versions to communicate. And really, this is kind of like a social construct uh or contract of like we want you to feel comfortable and versioning allows us to communicate like these these groupings of features, these groupings of capabilities and kind of mental models are all in this version and they might they may or may not change in a way that impacts you in this next version.

[00:13:22] Tim Neutkens: Yeah. So, um I think the React team does a pretty good job at uh versioning. Um, they also have like a lot less um like scope in the, like, because it's only rendering UI um and and doing all that, like all the stuff around it. Like it makes sense that they're like on a major version for a long time. Like I I wouldn't expect like a React, well, I'm actually like, you would expect React 18 that has like concurrent mode enabled by default or something like that. Or like some compatibility layer, um. This is all like speculative, right? Uh, but-

[00:13:58] Michael Chan: Sure.

[00:13:59] Tim Neutkens: Like React 17, for example, it's like, okay, there's no breaking changes, but there are like some, uh, like nuances to it, right? Like the new JSX transform that works slightly differently from what people have been doing before. Um, the, like the compatibility of like running multiple React applications in the same uh page. Under different routes, uh, and all that. Like,

[00:14:25] Michael Chan: yeah,

[00:14:25] Tim Neutkens: that's really important, uh, like incremental migration stuff that they put out in React 17, uh, that you don't immediately need per se, uh, but it does allow like for new approaches to be taken, right?

[00:14:38] Michael Chan: Yeah, I love that. Um, now one thing I wanted to touch on is that- or like go back to just a little bit- is, you know, you'd mentioned, um, that earlier on that that Next.js Conf had 70,000 people registered and you were supporting, you know, peaks of like 35,000 attendance at a given time. And so, I'm kind of curious. I mean, this streaming conferences is a fairly like new thing, um, given coronavirus and how we've like really been thrust into this. And it's interesting. Like I I I know a lot of people who kind of expect audiences of, you know, sub 10,000. And I think that there's probably a lot of platforms platforms that are designed for that. Um, what was your what was your experience putting on a conference that was gonna need to support, you know, about like, you know, 40,000 to 50,000 people?

[00:15:31] Tim Neutkens: Yeah, so going in, we knew that there were going to be like, there were 70,000 signups like at the day uh of the conference itself. So there could be a peak of 70,000 people watching at the same time, right? Um, in reality, obviously, like there's always like some dropout rate of people that just can't attend or it's like too early or too uh late for them uh in different countries, of course, because this is like all over the world, of course, because it's online.

[00:15:59] Michael Chan: Sure.

[00:15:59] Tim Neutkens: Um, but like we we started evaluating um a lot of the— uh like there there's a bunch of SaaS providers that are now like going into um the like virtual event space, right? Like building out virtual events and all that. Uh, but we weren't sure like if we could actually handle like that many people. Because like in a general conference, it's not going to be like, okay, we have a peak of 70,000 people. It's like we have a few thousand people, right?

[00:16:30] Michael Chan: Yeah.

[00:16:31] Tim Neutkens: There's a huge difference between like a few thousand people and 70,000. Um, so we we basically set out and we we knew that we had to build something ourselves Uh, so we went out and we started, uh, like we basically dogfooded our own uh platform, so the Vercel platform, uh, where you can host your Next.js applications, and Next.js itself. So, the conference platform for Next.js Conf was completely built on uh Next.js. Um, and one of the cool things about that was that we could basically dogfood all the new features in Next.js 10, uh, like the the image component.

[00:17:09] Michael Chan: Nice.

[00:17:09] Tim Neutkens: And uh, a lot of other new features. And uh by doing so, we could actually like verify like, okay, uh like we know Next.js can scale to millions of people, because we see it every day with like really large companies. Uh but we also had this case to like verify, okay, uh like we can run this type of conference on the Vercel platform, like no sweat. Like we we didn't have to do any like SRE type things, um like it all just like worked out on itself. Um, so so like that was a really nice thing to see. Um, and then the other cool thing is that we're now like wrapping up the uh the code that we built for the conference. So like the conference platform itself. And we're going to release that as a separate example or like a starter kit for building your own conference.

[00:18:03] Michael Chan: Nice.

[00:18:03] Tim Neutkens: So like if you want to uh like create a React podcast conference, you can actually do that.

[00:18:09] Michael Chan: Yeah, I mean, I wouldn't have to sustain nearly as many people as uh as you did, but yeah, absolutely. I think that's really interesting. And I think it goes back to how there you're you're starting to make more of these kind of predefined starter kits for um Next. And it seems like Next itself is becoming a little bit of a platform where you start with Next and then you can build onto it like these tailor-made things, whether that be commerce, whether that be a, you know, a a a conferencing solution. Um, it seems like more and more of the effort is going into these these tailorings of Next towards a specific need.

[00:18:51] Tim Neutkens: Yeah, for sure. Um, like a lot of our roadmap is is based on either like issues that we run into every day, like people having problems with a certain approach uh inside of Next.js. Uh so like an example of that is, uh in Next.js 10, we announced that you no longer have to use href and s on the um Next Link component. So you can just use href and it will automatically resolve that to the correct dynamic route.

[00:19:20] Michael Chan: Oh, nice.

[00:19:20] Tim Neutkens: Reduces a lot of friction if you ever used Next before uh using dynamic routes. Which is like the uh path segments, basically. Um like you had to manually provide like, oh, this is the page and this is the um like href that I want to go to. Um so there were those were two different things. And now it's just like, provide us the href and we'll figure it out for you automatically.

[00:19:42] Michael Chan: Nice, nice. You know, this this ties into a little bit of a, I don't know, like a a a thesis, I guess, or kind of a design perspective that I've been fleshing out over the last year, which is in React having a strong migration story as you go from like lowercase i components to uppercase I components. And how there's a natural tension- I think we've seen a lot of React libraries that go full in on React and do a wholesale replacement of some type of longstanding web- you know, something like like links, right? And it seems like with with the href, with what you're doing with images, which we'll we'll talk about soon, it's really kind of like narrowing down on how to make that migration path from the like lowercase um HTML element to the uppercase like component element a lot more, I guess, like virtuous or like a lot easier to kind of like switch those things on and off as needed. Uh we're kind of seeing this a little bit with href, making that a little bit more um like a regular uh href, um but then also with image. Could you talk a little bit about the design in making that migration and those mental models a little bit easier for people who are transitioning?

[00:21:01] Tim Neutkens: Yeah, for sure. Um so, like when we released the next/link component, uh initially, like that was back in uh 2016. Uh like end of 2016 when Next was released, the very first version had next/link. Um, and I was using the, like, sort of like the standards at the time. Like, React.cloneElement, like, on the, like, nested child, like, render props were not a thing. Yeah. Hooks were not a thing. Like, pretty much like all the things you know today were not a thing. Um, and, like, out of that came, like, you have to write, like, link and then, like, nest an a tag inside of there. But the href has to go on the link, and then the a tag is just like an a tag without any attributes. And it was fairly normal at the time. Um, so like over time, uh, we we added dynamic routes. So that basically allowed you to say like, okay, I want to have some like path segment going into, um, like say you have like /blog/slug or something like that, right? And then you want to replace the slug with hello world or like my own blog post, etc. Um, so that is something that we introduced later, and then we had to add in this property called as, which is like the href is the page, and then as is actually like the route that you want to go to.

[00:22:24] Michael Chan: Sure.

[00:22:25] Tim Neutkens: So then you have to link to like the page uh name instead of the like actual uh URL that you had. Uh, 'cause then like the router knows like, okay, this is the page I need to render this specific URL. Uh, and that also allows to to map different things, um, to a certain page. And then like over time, we actually realized like, okay, this is adding a lot of friction to like the end user, like the developer using Next.

[00:22:51] Michael Chan: Yeah.

[00:22:51] Tim Neutkens: Because either they forget and they get a different behavior than they wanted to, so that's like full page transitions. Uh, because like like if we can't find the page, uh, it would do a full page transition. Would still work as a transition, but it's not the same thing, uh exactly. Um, so basically, like, we wanted to reduce the friction that you have as a developer going from, like, okay, I'm going to do a link component with a href to a dynamic URL. Um, and that was something that came up quite often. So, like, we knew it was a pain point and we had to fix it. Um, and it it required some architectural changes as well, like, inside of Next.js core, like- Sure. We spent a few uh like weeks preparing towards that point, uh as it unlocked other features as well. Um so really like we're like now we're actually like driving into the direction of like, okay, we're going to have that same like sort of experience as like your native like a tag, for example, uh and it will just work for you automatically. So we're like lifting a lot of the work out of your hands. Same with the Next.js Image component, which we haven't talked about yet, which is a new component that was introduced in Next.js 10, where like you can just replace the uh img uh HTML tag inside of your JSX with Image, and it will generally work if you have a width and height set. Um and I'm saying if you have a width and height set, 'cause it does a few optimizations for you. So it allows you to prevent layout shift. So layout shift is this new uh web vital. Now I'm basically like throwing around words that you might not know, but if you go to web.dev and you look up for uh web vitals, you'll see that it's a new uh like standard that Google is using to— uh that's Google Google is going to use to index pages. Uh so-

[00:24:48] Michael Chan: Interesting.

[00:24:49] Tim Neutkens: Say you, uh like it basically checks for performance of a site, right? Like if your web vitals are good or core web vitals are good, uh it's generally an indicator of like your site is has a good uh fast experience. So that includes um Largest Contentful Paint, First Contentful Paint, and Cumulative Layout Shift. And Cumulative Layout Shift is basically this jumping around of items on your page when it's being loaded.

[00:25:21] Michael Chan: Yeah.

[00:25:21] Tim Neutkens: So we've all seen this, 'cause like everyone that has used the web has seen this before on any site. Uh not any site, but like on many sites, basically. Um where you load the page, especially like on mobile, then you start scrolling, and then it's like, I wasn't here when I stopped scrolling, but now it's like at the bottom of the page, or like at some completely different section of the article. And that's because of layout shift. So like ads come in later, um images come in later, and then like they take up the space that they wanted to, uh but the browser didn't know that it was going to take up that space when it was being requested. Um because like the developer had it marked like, okay, this is the space I'm going to need to render this image in this specific page. So that is what next-image helps you with. Like it it forces you to set a width and height. Uh, but then it allows you to- basically, that's like the the width and height that you would want to expect. But it's not like width and height on the image element, because uh it's not going to like wrap out of a a div, for example, or something like that. Like we have different layout options that allow you to choose which layout you're actually like supporting. Like if you want to have responsive images, you say layout responsive, and it's going to like uh stick with the the aspect ratio of the image, but it's not going to like scale down or scale up um in a way that you wouldn't expect to.

[00:26:48] Michael Chan: Interesting. I really I I like this, and and the Web Vitals um is is a really important tip because as far as I know, Google uh Google indexes pretty heavily on the performance of a site, um or at least that's taken into consideration quite a bit, uh maybe even more so than people would think. And so, knowing what the standards are and what the things are that the Google crawler is looking for in terms of a fast site could really provide a lot of value to people who want to optimize but don't really know what the most important things are. Um, I want to talk about a little bit more about the image optimization techniques specifically. Because I know it can be a little bit of a weird mental shift to think like, oh, I'm putting you know, these specific numbers in for width and height, um, but it's not actually going to necessarily be those, um, depending on my layout and whatnot. What are some of the things that that you're doing for people to optimize images? Um, and then also, like, what is WebP? I guess all of those kind of things that happen at the optimization phase, um, of the image component.

[00:28:01] Tim Neutkens: Yeah, for sure. Um, so like the Next.js Image component is basically like a layer on top of the like normal HTML image element. Uh, but we we try to like add in all the things that you would generally forget to add if you're building a site yourself. Like even if I would go and be like, okay, I'm going to build like the simple HTML page, uh, like the defaults of the image element um are like, okay, we're not going to lazy load. Everything is going to be uh requested immediately.

[00:28:33] Michael Chan: Gotcha.

[00:28:34] Tim Neutkens: And then, uh like it's all sent to the browser and it's going to display them all. Even if they're like way down in the page and like it's like maybe your your site is like a really long blog and then it has all the images loaded already. Uh but that like has some downsides, 'cause it's going to uh like take up network when you don't want to. Uh like 'cause other resources have to be loaded first. Um and it it also like generally adds in layout shift 'cause you don't have width and height set. And you're probably also not um serving the images in modern formats, like WebP or uh AVIF or or something like that. So this is like basically what we aim to solve with the Next Image component.

[00:29:18] Michael Chan: Hm.

[00:29:19] Tim Neutkens: Where the defaults are there Um, to basically help you get better performance, better Web Vitals. Uh, and then specifically layout shift and uh Largest Contentful Paint. Because um, going back to Web Vitals, uh just to to to give an example of that, Largest Contentful Paint is generally measured as like the largest element in the viewport when a page loads. And The largest element in general, like if you go to most websites, it's going to be like a really large image of something. Uh, could be a person like waving or something like that. Or it could be, like I don't know, if you go to my website, uh, there could be a picture of me, um, uh, and all that. So, uh, that image has a really big impact on that uh Largest Contentful Paint metric. 'Cause if that image loads in fast, the Largest Contentful Paint is going to be fast. So the image component actually allows you to- like if you start using it, it's lazy loaded by default. Uh that means it's only loading images that you can see, uh or that you're close to seeing. And then images that are in the initial viewport, you can say like, oh, this is a priority image. And when it's a priority image, you uh basically don't get the lazy loading behavior. You get the immediate loading. And we also inject a preload into the the head of the page. And this allows it to be like basically loaded as fast as possible. And we've seen like really big improvements in uh Largest Contentful Paint, like up to 50% in uh in some cases.

[00:31:00] Michael Chan: Wow.

[00:31:00] Tim Neutkens: Like in more cases than not, basically. So that's a really good outcome there. Um and then for all the other images on a page, like the images in the footer or uh like images in your blog post but they're like further down in the blog post, like those are all lazy loaded. And then the the width and height is needed to calculate the aspect ratio to make sure that the like space needed for the image is there when you're loading the page instead of when the page is like when the image is loaded, basically.

[00:31:33] Michael Chan: Interesting. Now this is this is fascinating because I've done a lot of you know design and frontend development. And images really are one of those things that you kind of have the best intentions about. But you know when push comes to shove, you kind of just get it up there and you're like, yeah, I'll fix it later. So, I really like this notion that you have like a really nice migration path. You know just using this you know the small i component to get it up there. But then you can upgrade and it to the large i image component and then have all of this capability to like really control the the the the size, quality, and speed of that image being loaded to to users.

[00:32:14] Tim Neutkens: Yeah, exactly. So, um, like so far we've only covered the like component itself, right? Like this is what the component does. Like throw in any image and it it would do that for you. Uh, but there's another aspect to this whole image component, which is Because Next.js allows you to handle the end-to-end, or that we handle the end-to-end basically for you. So that goes from like compiling your dev server, like your production server being started and all that. It allows us to add in extra functionality as well. So what we did was we implemented an image optimizer that works on demand, so it doesn't like increase build times, for example. Um, and it runs in development, it runs in production, uh, works anywhere, basically. Um, and that allows us to do more optimization. So you give us a uh URL, so like like /profile.png, for example, and that's a PNG. Uh, but when your browser uh tells us, because then what we do is like we Automatically prefix that URL with like our image optimization path. And then what we do inside of Next.js, the the production server, is actually um like take that URL, fetch the image, uh check what your browser supports. So uh if your browser, you know, basically all browsers, uh they publish in their Accept header, this is the format that I support for images. So that could be I support WebP. And it could also be like, WebP is not there, so WebP doesn't work. Uh WebP is this format that uh Google uh created, which is uh very like a lot smaller than the uh like general like PNG or JPEG, uh but without quality loss. So if we like convert those images Um, from the like original format into WebP and then serve that to browsers that support it, we actually reduce the amount of bytes that have to be sent. So you get smaller images, but without like any of the downsides basically. So Next.js has that built in. So we detect like, okay, you support WebP, here's the WebP image instead of the like original image. Um, and then also we support resizing the image. So we have this default set uh using srcset on the image element. Uh so it's all like web standards, basically, um that allows you to— uh like when you create this image, and you just put in the same URL that you did with the normal image tag, it's going to create smaller versions of that image for uh like smaller browsers, right? So For your phone, for your tablet, for your laptop, and then also for desktop. Uh, and it does it automatically. So you don't have to configure anything. You um don't have to like go in and know about all these different things like srcsets and and all that. Uh, but it will just work automatically. So basically, um, what this allows us to do is like serve smaller images. Across the board because if you're on a phone, like the image being displayed is generally smaller than if you're on your laptop, right? Um, but generally, like we forget to do all these optimizations because they're really hard to do, right? You have to set up these different build tools. Um, you have to know about Azure CSS, you have to configure Azure CSS that makes sure that it happens for all the images that you're using on a page.

[00:36:00] Michael Chan: Yep.

[00:36:01] Tim Neutkens: Um, and this this could be in like different components, different uh layouts, all that. So it becomes really hard. And then what Next allows you to do is just use Next Image and then uh like a lot of that work is abstracted away from you, uh allowing you to focus on just like, okay, I need an image here and that's it.

[00:36:21] Michael Chan: I do think that's super interesting, especially that it's integrated in kind of that that that full stack Next framework. Um 'cause there are services that do this, but that the handoff is not always Uh delightful. Right? And it really is nice to just kind of have your images kind of where you expect them to be. And then have Next, the framework, really figure out all of the benefits. And I think specifically with with WebP, I know a lot of people have wanted to try embracing that. But like actually doing that is so complicated. It's almost never really worth the time. So to get that for free um is really is really interesting.

[00:37:01] Tim Neutkens: Yeah, exactly. So uh we did some research, and HTTP Archive has some data on images. And uh it's basically 0.3% of images uh is using WebP currently.

[00:37:17] Michael Chan: Wow.

[00:37:18] Tim Neutkens: So that's- it's still quite a few websites, but it's it's not enough, right, if you're wanting to optimize in that way. Um and then even like- Uh, like newer image formats like AVIF, um, which uh, like Netflix is adopting and uh, like the the Chrome team is also pushing for now, um, is even smaller than WebP, but with like even less quality loss. So, um, like that's a format that we're going to support in the future. Um, and all you have to do is upgrade next. To leverage those, right? So like you you don't have to know about like what AVIF is, um but we'll automatically like know if your browser supports it and then we'll serve it to them, um where possible.

[00:38:05] Michael Chan: Awesome. Now in terms of deployment targets, um I know that obviously obviously all this stuff is gonna work with Vercel. Um are there other um deployment targets at this point where features like this are gonna work like right out of the box?

[00:38:19] Tim Neutkens: Yeah, so um Next can be deployed anywhere uh that supports Node.js hosting. So that means like if you're running Docker or uh like you're you're putting it on Heroku or like anywhere else, um it's going to work, 'cause you're just using like the Next.js Node.js server and then we set the correct cache control headers, we we do everything uh uh the same way that you would do it on Vercel, for example. Um, but on Vercel, you get a few benefits there, which is that you don't have to manage your own infrastructure. So you don't have to worry about, like, okay, can I actually scale this, like, thousands of images that I have, like, on the disk, uh, that I I put in, um, into, like, my my Docker container. And then also, you don't have to worry about, like, scaling up the application, uh, because it all, like, all the Next.js pages become on serverless functions, uh which can uh scale infinitely. So like your um uh like the bottleneck basically becomes your database, not so much the like platform you're hosting the code on. So like really like you can host Next.js uh anywhere you want. Uh many like companies host it on their own uh like private infrastructure or like some other uh cloud provider. Uh, but once you host on uh Vercel, you basically get a complete workflow from end to end where uh like if you do a commit on your uh GitHub branch, you get a automatic um preview deployment. You can review that and then put it into production basically. Um, so that is being done by by some really large companies as well. Um, I'm not sure if I can share which exactly, so I I'll I'll not say right now. Sure. Potentially I can uh put that into the show notes. Um and yeah, so the image optimization works like anywhere you want to host, um as long as it's not using uh Next export, so static uh exporting, 'cause we don't do the image optimization at build time, like I explained. Um it runs on demand. Uh the reason for that is that we didn't want to uh basically make your builds slower. Um even for static generation of uh of pages, 'cause uh image optimization is quite resource intensive, especially if you want to optimize all images at the same time, like in a build pipeline, for example. Uh so like we don't want to make your build times, like I don't know, 15, 20, 30 minutes just because you have many images, right?

[00:40:55] Michael Chan: Right, right.

[00:40:56] Tim Neutkens: And that's especially true when you have a CMS powering your website and like people are uploading images and all that. And it also doesn't keep, uh like you're like you never reach the limit of the amount of images on your site if you have dynamic content, right? So, uh like say you have a blog, like you keep adding blog posts, so like every blog post you would add, you would add in more build time. Uh and we're trying to avoid that basically, like by doing the image optimization on demand when a user requests it, and then like we cache it automatically.

[00:41:28] Michael Chan: Yeah, I think that's super important. I mean, 'cause so much of this goes back to, you know, things that are difficult or painful, you know, you're not gonna do. And I really like this as a design constraint of Next, is trying to find those places to like make it as easy as possible. Do it in that way and keep, you know, keep things fast and and ensure that we will do them uh as a result. You mentioned something that I wanted to touch on in that because of these full-stack solutions, There can be- there's a differentiation between, you know, static content and dynamic content. And images kind of sit at the intersection of that. And I wanted to talk- I know we're kind of like kind of, you know, careening towards the end of our time today. But I wanted to talk a little bit about how Next is handling that. How you can kind of take just certain trees and treat them as like a very statically statically generated part. But then keep other parts like perfectly dynamic. Could you talk- to those um APIs for a little bit?

[00:42:32] Tim Neutkens: Yeah, sure. So in Next.js 9.3, we introduced uh getServerSideProps and getStaticProps. And getServerSideProps allows you to do server-side rendering, which uh Next has always been able to do. Uh so it pre-renders the content for every single request that comes in. And then the opposite of that is getStaticProps, which allows you to pre-render content at build time. And then serve the same generated content to end users. Hm. And then uh in Next.js 9.5, we actually introduced incremental static generation, which means like you deploy your Next.js app, uh you can generate some content at build time, but you can also generate static pages on demand. Uh and that's only like a single property that you have to add, which is revalidate. That allows you to set a timeout for, okay, I want to regenerate these uh this content for this page every so many seconds, basically.

[00:43:33] Michael Chan: Nice. Nice. I love that. Um, cool. Well, you know, we're kind of getting to um the the point in the show where I said I'd let you go. Um, but I want to ask you before we before we let you let you go, um, what are you most excited about in the next you know, 2, 3, 4 years kind of timeline. Um, obviously, you've been really chugging along and doing some really good work and incrementally getting Next to a place uh that has great um developer experience, but then also amazing ergonomics for um for customers and people experiencing the web. Um, what are you excited about coming up on the on the horizon?

[00:44:16] Tim Neutkens: Yeah, so really, like, our uh focus has always been on like end user experience and developer experience. So uh we focused a lot of resources this year on improving end user experience by reducing the amount of JavaScript and also um improving developer experience by giving you things like fast refresh, which was available inside of uh Facebook, uh was developed uh inside of Facebook. Um, and you couldn't really use in the like open source React space. Uh, so basically like we set out and we built uh the fast refresh support, like all the bits needed for it to be uh to exist in open source, and then implemented it inside of Next.js uh and shipped that, uh which is showing great results uh in developer experience space. Um, 'cause it allows you to keep the uh state for, uh, like, say you're making some edits inside of your code, it's going to keep the state and it's also going to be resilient to errors. Like, maybe you make a typo, it's going to, like, preserve the state across typos as well. So, like, if you make a typo, it crashes your app, uh, and then you fix the typo, it's going to be right back where you were. Uh, if you were like-

[00:45:36] Michael Chan: Oh, nice.

[00:45:36] Tim Neutkens: Typing something in, um, uh, in a in a form, for example, you have that in state, uh, the state will still be there. Um, so it really makes you more productive in that way. Um, it also is more reliable because it's hooked into React itself, uh, which basically like makes React aware of like, okay, this is a hot update, so like you're you're going to refresh the code of this underlying component. Uh, so we work with the Facebook team, uh, like the Facebook React team, uh, on this specific uh bit. And and that's showing some great results. So like, looking to the future, like we're going to keep improving this. Like we introduced a new error overlay that uh has more accurate errors when something happens. Uh, like say you make a typo in your CSS, that's now uh a very nice error. Um, the uh like I don't know, like importing the wrong um like module, like maybe you you made a typo in the module name, like that's going to be uh shown in a better way now, um uh and things like that. So we're going to keep improving those. Uh and then we're also going to basically help uh you achieve the uh the things that you wanted to do uh anyway, but in a faster way, right? Like Uh, like, an example of that is the image component. Like, maybe you wanted to optimize images, but it was really hard to do that. Uh, and we introduced features for those uh specific cases. Uh, another case of that is, for example, in Next.js 10, we introduced uh internationalized routing. And internationalized routing is not the full solution yet, uh, but it just gives you the routing part of internationalization. So that means that you can use any React translation library and then use Internationalized Routing to handle the the routing bit of uh that in particular for your Next.js application. Uh so we're planning out to provide more resources for that, um so improve the developer experience of uh internationalizing your application even more uh by like providing the the tools for like Translation loading, for example, is a big issue. Um, like, it requires a lot of custom code and like know-how of like, okay, this goes here and then like it has to go there because hydration and all that, right? Yeah. So, like, we're going to provide more uh more resources for that uh in examples and also uh built-in features. Uh, like, we're also always listening to the community. Uh, so, like, if there's Many people saying like, okay, like I'm running into this like every single day when I'm working on a Next.js app, like we're likely to fix that. Um, and besides that, like we we introduced uh another like interesting project as well, which is uh Next.js Analytics, uh which is a service uh from Vercel that you can use for any Next.js application. So even if you're not hosting on Vercel, That allows you to track performance over time. So what I mean by that is, uh like Google is going to use uh Web Vitals to uh rank search, uh like rank inside of search. Uh and what uh they they basically do is like they they basically refer to like real user experience. And real user experience is uh like calculated by uh CRUX, which is C-R-U-X. Uh which you might want to look up. Um and that basically holds the like Core Web Vitals for like general um pages like from general end users. Mm-hm. Right? So um that is uh like something that you can't really access and measure yourself over time. So Nexus Analytics allows you to keep track of these performance metrics In a very easy way, like all you have to do is uh enable it if you're using Vercel or um set up like a single key uh inside of your Next config. Um and then like it's going to keep track of your end user experience over time. Uh and then we'll give you scores, we'll give you— um so like the score is like the real user experience score. And it's basically something that you can improve. over time, uh and then also stay fast over time. So, uh like maybe you spend like a full week with your team on improving performance, and you want to know if your end users are actually benefiting from that, right? So, um Next.js Analytics allows you to track those types of improvements. Another is like maybe like someone does a pull request that uh introduces a massive image on your homepage. And uh all your end users are suffering from this, um because like this 10MB image takes a lot of time to load. So like the the the metrics of that specific page are going down, right? So Next.js Analytics allows you to um like see that score going down. And uh we're also going to introduce like alerting on that, basically. So it allows you to make sure that your site is going to be fast over time. Uh, which really fits into this like whole vision of like Next.js helping you to be more performant, um, and allows you to to focus on like keep improving your application over time as well.

[00:51:15] Michael Chan: Yeah. It's it's really wild to see how much y'all have been up to. And I think You know, something that we barely even scratched the surface on is the value of Next being this project that sits in between, you know, Facebook and Google. Which I think is, you know, a place where a lot of, you know, web developers sit, right? They're sitting kind of like in between, you know, React as a build tool, but then- or a UI development tool. Um and then Google, who's actually you know ranking their pages, you know directing people to them, um making sure— kind of exposing some of the information that makes those those pages fast and rank well. And you know Next is really sitting at the middle of that and kind of you know holding the hands of of of both parties and developing solutions in a way that makes that easy for people who really just want to make make a site, wanna make a commerce platform, wanna put on a conference, like whatever you wanna do that you might need to make a- might need to build a website for, um, y'all are taking the things that you learn and the new tools from both parties and making and building those into Next. And I just, I love seeing that.

[00:52:34] Tim Neutkens: Yeah, definitely. So, um, like we we collaborate very closely with uh both of those teams, um, like the Google Chrome team, there's a team inside of uh the Chrome team that is working full-time on Next. So they're basically helping uh like provide these like really large performance uh improvements, like the the image component. Um and they're basically— like the reason that they they do that work is that, like obviously like you can uh introduce a lot of um like new standards and like try to push people towards these new standards uh and all that. Uh, but people are still building like React applications or um like applications in different frameworks. So, uh basically like inside of the Chrome team, they they decided like, okay, like maybe we we need to like continue our like um uh like the the standardization process, right? Like that that's working out great. But uh like that team is really big. Uh the Chrome team. So, they were basically like, okay, maybe we also need to spend some resources on like the framework ecosystem where um like we can actually push like some of these really large sites that are, for example, built on top of Next.js, um to uh implement all these like improvements that are um like affecting the whole ecosystem. Like, an example of that is, can you improve what Webpack gives you out of the box, right? So an example of that is, um, in Next.js 9.2, we introduced better uh code splitting. Um, so like we made the uh Webpack chunks algorithm smarter through uh many, many uh hours of testing and Figuring out lab data and and all that. Uh like someone on the Chrome team did that. Um and eventually they found like, okay, if we change these settings inside of the webpack config, uh it's going to reduce um the amount of JavaScript being loaded by like 30 to 70%, depending on your application. Uh which is massive, right? Like on a a large application with no code changes at all, it's a large uh improvement. Uh, so like all they had, like all the Next.js users had to do was like upgrade their application. And then they would get this like improvement in uh performance for their application without doing like any work. Um.

[00:55:14] Michael Chan: Hmm.

[00:55:15] Tim Neutkens: So then it's like, okay, that's a nice uh improvement on Next itself, right? But like, how does the rest of the ecosystem uh like improve based on this? Uh, so like they also worked with other frameworks to introduce this improvement, uh, so like Angular and and others. Um, and they also, uh, like the new Webpack 5 chunks algorithm is actually like more so based on uh what was built into Next uh like 1.5 years ago or so. So-

[00:55:47] Michael Chan: Interesting.

[00:55:48] Tim Neutkens: Like there's a really like big ecosystem factor into uh doing these types of improvements, uh like um like figuring out like what is a good improvement. Uh like the Image component, we're seeing some like really big performance improvements for uh like either small apps uh but also like really large apps that have a lot of images. Uh because they like even if they had like many images, it could be that the uh like developers didn't think about like, okay, maybe we have to lazy load them all. Um or like maybe we don't have to lazy load the top row, right? Like maybe you want to display like all these images like really fast 'cause they are critical for uh the experience. Like I don't know if I go to IKEA and uh I've I've been spending a lot of time on the IKEA website 'cause I'm moving. Um and uh you you basically see like these really large images like in the initial viewport. And I'm generally waiting for those images to load because I want to see what's on them, right? Um, and then I'm going to go into the website. So the faster those images load, the like faster I'm going through the website. Um, and that's just one example, right? Like there's many different layouts and many different uh ways that images are being used. So, um, yeah, that's that's basically like something that that we're seeing that is just like Okay, we can actually make a really big impact. And then also because Next is being used in uh like such large applications, like uh like the the largest news website in China, um like uh many very large websites in the US, uh like all over Europe. Uh we're even seeing like uh government corona dashboards. Um Uh, like a fun one was the the Dutch government, like I live in the Netherlands, uh, I'm Dutch, like the the Dutch government is using Next.js to uh show the like corona uh statistics.

[00:57:53] Michael Chan: Oh, nice.

[00:57:53] Tim Neutkens: And yeah, we're seeing just like everything, um, uh, like we're we're seeing everything from like small sites, like one-pagers, uh, like a corona dashboard to like massive sites, billions of users uh every year and Uh, yeah, so it's it's really large uh surface of of impact, basically, like these like smaller changes that are seemingly small uh can make.

[00:58:18] Michael Chan: Yeah, they have really big kind of like secondary effects and like a huge impact across our understanding as an industry about how to how to navigate these important things, but in with the tooling that we have, you know, Webpack, React, um, you know, serverless, et cetera. So as— if people want to know more about Next 10 or Vercel or your work, um where are some good places for people to learn more, get involved, et cetera?

[00:58:48] Tim Neutkens: Yeah, so if you want to learn more about Next.js and you haven't used it before, I would recommend going to nextjs.org/learn, which is our interactive learn course where uh you actually like build out a Next.js application. Um, interactively, so you can follow along and uh try it out. Uh, if you do have used Next.js before, um, you you can go to uh nextjs.org/ten, which will will send you to the the Next.js 10 blog post. Um, and I would also, like, if you're like more so a visual watcher, like you can also watch the Next.js Conf keynote. Which we'll put in the show notes.

[00:59:31] Michael Chan: Yep, we'll link that.

[00:59:33] Tim Neutkens: That is like a more like conference keynote type uh like overview of the the Next.js uh 10 release.

[00:59:41] Michael Chan: Awesome, awesome. Now, where do people find you about the internet?

[00:59:45] Tim Neutkens: Uh so just my full name on pretty much any platform uh you could think of. Um so that's uh on Twitter, on Uh, like GitHub, uh, et cetera. And yeah, that's that's about it.

[01:00:00] Michael Chan: Perfect. Perfect. We'll link that too. Awesome. Well, hey, Tim, thanks so much for your time today. I really appreciate it. And I know that a lot of people will be really excited to have a little bit more in-depth look at the uh the things that you've been working on and all of the effort across organizations that it took um to get us here. So Uh, thanks again.

[01:00:20] Tim Neutkens: Thanks for having me.

[01:00:22] Michael Chan: This has been episode 121 of React Podcast with Chantastic and guest Tim Neutken. A transcript for this episode has been sponsored by Ben Myers. Thanks, Ben. It's been a tremendous honor getting to know Ben as we've worked together on the React Podcast community in Discord. He gave my absolute favorite talk of the year, Hijacking Screen Readers with CSS, I strongly recommend that you check out his writing at BenMeyers.dev. If you'd like to support the show by ordering a transcript, send me a DM at @chantastic or @reactpodcast. You can find the transcript for this episode, links, and show notes at reactpodcast.com/121. Thanks to those who supported this episode, Honeybadger and Infinite Red. When your deployments go sideways, you want Honeybadger at your back. Honeybadger gives you DevOps superpowers by combining error monitoring, uptime monitoring, cron monitoring, external service and job monitoring, all into a single, easy-to-use platform. Give Honeybadger a try today. Visit honeybadger.io, mention React Podcast at signup, and get 30% off for 6 months. Again, that's honeybadger.io. Infinite Red is your friendly expert resource for React and React Native. They've worked with developers and entrepreneurs like you to design, build, and ship quality apps. And they've been doing it for over 10 years. Infinite Red will give you $750 when you start or refer a new project. Get expert React and React Native help at reactpodcast.infinite.red. If you like this show, there's a fast, free way way to demonstrate your support. Leave us a review on iTunes. It's the best way for you to let me know what you think we're doing right and what we can improve. 2 to 3 minutes of your time helps us make the best show we possibly can. As always, links and show notes for all episodes are available at reactpodcast.com. This episode was edited by Mikael Delport. It was produced by Mikael Delport and Sarah Jackson at Speck, a network to help you level up in design and development. Check out spec.fm for other shows that are sure to fast-track your career. I'm your friend, Chantastic. Thanks for listening. We'll be in your ears again next week.