chantastic.fm

99: Michael Jackson and Ryan Florence on Remix

Episode 99 · July 2, 2020 · 01:09:20

Hosted by chantastic · With Michael Jackson and Ryan Florence

Sponsored by Infinite Red

Download MP3 · Jump to transcript

Featuring

Sponsors

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 Chantastic. Today, friends of the show Michael Jackson and Ryan Florence join us to talk about Remix, a killer React framework from the creators of React Router. This is a two-part conversation. Today we dive into the technical challenges of building a React framework and why the now ancient ideas found in Turbolinks and Pjacks could be the key to high-performance server-side rendered and generated React apps. First, a big thanks to this week's sponsor, Infinite Red. Do you bang your head against your keyboard thinking, this would be a whole lot easier if I could just work with someone on the React or React Native core teams? I definitely do. Having that access to developers that know React inside and out and know the direction the library is headed has been a force multiplier for my work. If you don't have that, you need to find it. And I recommend starting with Infinite Red. Infinite Red are core contributors to React Native and have expert React experience. They've been designing, building, and shipping apps for 10 years and wanna help you navigate the hardest parts. They have a pretty sweet deal going right now where you get $750 for referring new projects. So, if you know a team in need, this is a good time for you. Get expert help today at reactpodcast.infinite.red. And now, into the show. Michael and Ryan, welcome to React Podcast.

[00:01:44] Michael Jackson: Thanks, happy to be here. Thanks.

[00:01:46] Michael Chan: I've I've I I I real I'm realizing just now that I've never had to like invite, or maybe one time before, invited uh 2 people to the podcast and it felt it felt awkward. So, thanks for giving me that.

[00:01:58] Michael Jackson: Well, when you're kind of you're kind of lacking, you know, in star power, you got to invite two people to kind of make up for the, you know, the lack of illumination.

[00:02:08] Michael Chan: Well, this will be a fun experiment. I've I've not done this in a while, so we'll we'll we'll kind of like feel this out as we go through. But um y'all are announcing this really cool project, and I just wanted to get you both on to talk about it, uh kind of answer some of the questions that I had, some of the interest and intrigue around the project and see see what's going on. So, um, tell me a little bit about Remix. Just the high level and then we'll kind of like dive in from there.

[00:02:36] Ryan Florence: Yeah. So, um, as you know, Michael and I have been doing React for like almost since the beginning.

[00:02:43] Michael Jackson: In the beginning.

[00:02:45] Ryan Florence: Yeah. And uh we've and the the two of us have been working together for 5 years. Um. Traveling the world. Uh, hotel— I've had more sleepovers with Michael than anyone else in my life. And uh—

[00:02:59] Michael Jackson: And P90X3.

[00:03:01] Ryan Florence: We've done P90X3 together at hotel rooms across the world.

[00:03:05] Michael Chan: You've had multiple seasons of P90X together. Like different workouts.

[00:03:10] Ryan Florence: Um, but anyway, so like we've we've spent a lot of time together. And um, and we built React Router together. And React Router was always was always just like the core of what we really wanted to build. Um and and that's Remix, uh which would be a framework on top of React, on top of the ideas of React Router, on on how we think um you can deliver really great um dynamic user experiences um without having to like goof around with you know, all the all the DevOps, I guess, quote, part of JavaScript app development. Like just just throw some files in a folder, um create some React components and say Remix run, and then it'll just do everything else for you. Um uh so, yeah, yeah, a framework built on top of React and React Router, uh with with data loading and code splitting and just just all that kind of stuff. The the kind of like the the core app framework that you would want to build a high-performance and interactive and dynamic React application.

[00:04:18] Michael Chan: Interesting. Now, I know that there's a lot of, I guess, different philosophies in the space of like React framework, right? Like you have you have Next, which is kind of like popularized this idea of of like a file system-based framework. You got Create React App, which is kind of the You know, you know, Facebook's way of like building uh or or an idea of like how you would like build a React app. You have Gatsby, which is like a full-on like content management cyborg thing that kind of just happens to use React. And um and so, there's a lot of like philosophies. And it seems like even now, there's a lot of work happening in this idea of treating the client and the server as one. And it feels kind of like from what I've heard that this is a lot of like the philosophy that that you're working towards is how do we how do we get that handoff to be a little bit more seamless? Like I don't want to have to think about like you know hydration or or getting the getting the data in a certain way on the on the client or the server and then doing all that kind of stuff. I just want it to be solved for me. Like do you feel like that's kind of the space that that frameworks in this like React space are needing to go toward?

[00:05:31] Michael Jackson: Yeah, it's a it's a huge question, right? I think it's it's a hard nut to crack. Um, some some frameworks like Create React App just decided, you know what, we're not even gonna we're not even gonna mess with the server.

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

[00:05:46] Michael Jackson: Uh, we're not we're not we're not gonna mess with the um, you know, server rendering pages. Um, and and a lot of React Router users, you know, React Router is built for single-page apps. You know, the history library, everything we talked about last time, last time I was on the podcast, all of that stuff happens on the client. And we have an API in React Router for rendering server-side apps with React Router. But the truth is that that's really just the tip of the iceberg. You know, yeah, you can render your routes on the server, but you know What about all that data? Um, and then once your app grows large, well, how are you doing code splitting with all of the different routes you have? You know, are you including all of those in your initial bundle, or are you able to, you know, progressively sort of load them as as the user navigates around the app? Um, same thing with, you know, the bundles that you're generating. Um, so it's, it's, I I think the the reason that it's uh so hot right now is because now we've all got kind of a couple of years' worth of experience with React.

[00:06:54] Michael Chan: Yeah.

[00:06:55] Michael Jackson: And we're kind of looking around saying, okay, um, you know, Facebook will kind of talk about, um, you know, at React Conf, they'll kind of talk about some of the things that they're doing, but really the, the open source pieces are GraphQL, uh, React, uh, Metro, but there's, it's, there, there's not a really sort of cohesive piece that kind of puts it all together for you. Um unless you're unless you are using one of the one of the frameworks that's out there, right, like Next or Gatsby or something like that. And then all of the framework creators' opinions come into play, you know, whatever they think is the most important thing to focus on.

[00:07:33] Ryan Florence: I think that's actually a really good uh definition of Remix too, is it's you go to Facebook's React conference, they talk about all the cool things that they do with React and data loading and all that kind of stuff, and And then you go home and you're like, well, I want to play too.

[00:07:48] Michael Chan: Yeah, yeah, yeah. Where's my big pipe?

[00:07:51] Ryan Florence: Yeah, exactly. Yeah. So, so Remix is sort of like the Facebook infrastructure for the rest of us.

[00:07:58] Michael Jackson: Fetch as you render as you fetch as you route.

[00:08:02] Michael Chan: I doubt that you're gonna be able to uh like copyright that. But um. So, what are some of the pieces then that that are missing? Or I guess some of the pieces that need to be figured out in order to create a framework. So so things that are kind of shared, I guess, even in with the libraries that already exist. Like so you need some kind of routing, right? And then like like what else?

[00:08:26] Ryan Florence: Yeah, so uh and you said something a little bit earlier where you were saying that these frameworks are kind of like trying to treat the server and the client as one, like kind of it's the same world. Um and uh uh just just as we've been developing Remix, uh what's what's kind of interesting is we actually are drawing way more inspiration from Rails, probably, than Next or Gatsby or Create React App or anything that we've done in React before. Um, and if you if you've done Rails, then you know about a thing called Turbolinks.

[00:08:59] Michael Chan: Yes.

[00:09:00] Ryan Florence: And Turbolinks is the Rails version of let's treat the client and the server as one. Uh, so if if you're unfamiliar with it, uh Turbolinks basically allows you to build all your pages with Ruby, And and and Rails, and it'll deliver those pages. And then when the user clicks a link, uh you you don't have to like do any JavaScript to go and get the new page and load the data or any of that kind of stuff. Um Rails is just gonna go to um to its server and have Ruby render the new page for you. And then you're gonna get that new page as XML or HTML. And then they've got some JavaScript built into Turbolinks that just like You can think of it like the virtual DOM diff of React, right? Or or it really just document.body, innerHTML, kaboom.

[00:09:48] Michael Chan: Just nukes it.

[00:09:49] Ryan Florence: Yeah. But but that's still like— that's just to me, that's the right model. Like I I don't want to have to think— and and this is what you run into with the current frameworks that server render React— is you got to think I'm loading data. Am I loading this from the browser? Or am I loading this from the server? If I'm on the server, I would rather just like go straight to the database and get that data. Um, if I'm on the client, well, then all I have is fetch and maybe mixed with some other sort of thing. So there there's this like, you can almost get there. But if you try to do your data fetching the same and uh with like the same code in both places, it gets it gets really difficult. Um, and so one of the one of the missing pieces, to get to your question, is data. How do you get- Yeah. Your data into the page uh when you initially render? And how do you get data into the page when you click on a link? Um and and should you just go ahead and do a full page reload and do it the same every time? Um so so that's that's a big that's a big nut to crack, um is is data for both the initial render and then also for the transitions between routes.

[00:10:54] Michael Chan: Well, it's really interesting that you bring up Turbolinks. Because I've always thought that this was a really fascinating technology in Rails, right? And and it I don't know. At the time, it kind of felt like a little bit weird. Or like even Pjax, right? I feel like that's what- Pjax? Yeah.

[00:11:10] Ryan Florence: I

[00:11:11] Michael Jackson: haven't heard that in forever.

[00:11:12] Michael Chan: So there's like uh uh Turbolinks and Pjax. And and they were pretty aggressive.

[00:11:18] Ryan Florence: We might as well be saying like COBOL right now to a lot of web developers. I know.

[00:11:22] Michael Jackson: People are like-

[00:11:23] Ryan Florence: I've heard of Rails.

[00:11:26] Michael Jackson: They didn't teach you that in code school.

[00:11:28] Michael Chan: Basically, like, all it did, it was it would hijack all your links, right? And it would turn like your regular anchors into like, it would fetch and then like like you said, just replace the replace the body, but leave all the CSS and JavaScript kind of already processed.

[00:11:42] Ryan Florence: Yeah. Because that's what you save. Then you don't have to re-download that JavaScript. Or even if it's even if it's cached, your browser still makes a request to say, hey, do I still need this? And then it comes back with a 303, like, no, it's unchanged.

[00:11:55] Michael Chan: You got it. You're good.

[00:11:56] Ryan Florence: Yeah. Yeah.

[00:11:57] Michael Chan: And so, like, I love this idea, but it it seems like paired with what Rails has done from the very beginning, right? Like, if you look at that first, like, 2013— re— sorry, I said Rails— React keynote, like, one of the big things that they talk about is this concept of, like, hydration, right? Like, that you can render React, like, on the server and then, like, kind of, like, write over it just as easily as if you had, like, written— oh, right, rendered it on the client for the first time. And so, it feels like there's there's definitely something there, right? Because like yeah React is almost like a really good Turbolinks, right? Like you said, just kind of picking out and like replacing the pieces that would need to be changed instead of doing the whole like you know replace the replace the document body.

[00:12:39] Ryan Florence: Yeah, and see, and that's that's where you like get dropped off at a cliff with React is like, oh, but what about the data I just loaded on my server? Right? And like that's that's the thing. And so it's like, okay, well, just don't send it. Uh, okay. Well, now I've rendered like maybe a nav. Maybe.

[00:13:00] Michael Jackson: Just render a spinner and then in your useEffect or your componentDidMount or whatever, you'll go and fetch it.

[00:13:06] Ryan Florence: Yeah. So, at that point, what's what is the point of even server rendering the thing if all you like you could have just dumped a shell in your index.html thing and then replaced the thing when React shows up. Yeah.

[00:13:16] Michael Jackson: Uh, one other thing that you said Michael was- you talked about- or sorry, I think it was Ryan said we're drawing a lot of inspiration from Rails. I would like to say that, you know, we're drawing a lot of inspiration from from PHP as well. I feel like I I really do. Like, um, you know, there was a lot of stuff that hap- like like like the file name-based routing, like like for example, right? First time I ever did that was uh I was using a PHP framework called CodeIgniter. And then I used Zend.

[00:13:49] Ryan Florence: That was a good one.

[00:13:50] Michael Jackson: Yeah. And then I used Zend framework and they did kind of a similar thing. And it was and and I it was so nice with my little Apache server, 'cause I would just name a file something, you know, profile.php or whatever. And now I would have a profile page that I you know that I could punch in the URL and I could browse to that page. So, um, you know, these are these are there are a lot of kind of old ideas here. And I feel like we kind of leapt forward uh by a lot when React came on the scene, because we finally learned how to manage um state and the UI in a stateful way and and suck the state out of the UI. Um and it was so nice that everybody just wanted to build stuff with React, but it kind of it I guess took a while for us to um kind of merge the two worlds. If you will, because there was so much good stuff.

[00:14:43] Ryan Florence: Yeah, it's easy to look at like where we're at with React and be like, oh, we we forgot all the great things about the web and this is ridiculous. And like, and look how hard it is to try to do what we used to do in PHP in React. Like, this is ridiculous. But like, go back then and I was building super interactive applications with JavaScript back then too. And that part was dang hard. Mhm.

[00:15:06] Michael Chan: Yeah.

[00:15:06] Ryan Florence: Right. So React has made this part super easy. But it has its own trade-off. But uh to try to like do the kind of interactions that we can do now with React, like in 10 minutes, would have taken a month of development time to have the same uh runtime performance that React has. Like when you're goofing around with elements all yourself, not not for like a small animation or a little form validation, but like some of the really robust um kinds of interactions that you can get. That part, that part is way easier now in React. So it's like the the backend piece was a lot easier before React showed up, but the frontend piece was really difficult. React shows up and we really wanted to build these nice dynamic apps. And so React made that easy. But now the backend piece and the data and the server render and all that is really difficult. And so now, you know, 5 years later, to me it's like, okay, it's not that we were doing dumb things in Rails. Rails is awesome. We weren't doing dumb things in CodeIgniter and PHP. That stuff that was all good stuff. We just now know what our constraints are uh for this new frontend stuff, too. And let's let's bring these two worlds together. And that's that's what I feel like Michael and I are trying to do with Remix.

[00:16:15] Michael Chan: Yeah, yeah, yeah. I love that uh we've we've now just turned everyone off to this show. We went all the way down to PHP. Like nobody's listening anymore.

[00:16:25] Michael Jackson: This was the React podcast.

[00:16:27] Michael Chan: Old guys talking about the way software used to be.

[00:16:35] Michael Jackson: Remix is also a couple of other- so like that's kind of like, I feel like getting to a lot of the meat of it. There are also a lot of other kind of nice things that we're kind of throwing in there. Like, so uh so a couple weeks ago in our newsletter, Ryan demoed this scroll management piece. And it's something that you should be doing. It's something that every web app should be doing. Um, and it's something that typically in React Router land, we have said, this is how we would expect you to do it, right? Like, we're gonna give you this hammer and this saw, and we're gonna give you these tools. One of them is the location key, right? We're gonna give you this tool here, and you can use that to manage the scroll position in a nice way. You know, you can save it to session storage and restore it when the user gets back to that page and everything. And uh and and part of Remix is, you know, we're kind of looking around and like, you know what, like we're not 100% sure that that this is really catching on. And and we think that we could actually do a lot more for people. Um instead of telling them how to do it, like why don't we just give them a hook, right? And and we can't do that though unless we own more of the stack. We can't do that unless we know, uh, you know, we have a lot of other opinions about, okay, here's how you're gonna build, uh, your web app. Um, and and so just stuff like that that we're including in in Remix that is, I feel like, kind of the, you know, it it gives us the opportunity to, instead of just saying, here's how you can do this, to just say, here, here's a here's a hook. We did it for you.

[00:18:14] Ryan Florence: Yeah, because uh like like with scroll position in particular, Um, at a high level, it's super easy to understand. The user clicks back, the location changes. If the location's different, then put the scroll position back to where it was. Uh, so why doesn't React Router just ship with something like that? Well, if you click back and you don't have a data cache to be able to render the page the way it looked last time the user was looking at it, then React Router can't restore the scroll position for you. Because it doesn't know when your data is there or if it's gonna be there.

[00:18:47] Michael Chan: Right.

[00:18:48] Ryan Florence: And so, it doesn't know when to do it. Um, so, with Remix, we actually have a data cache. So, when you click the back button, we know now, because we designed the cache, that your whole page is gonna look exactly the way that it looked last time that the user was there. And so, now we can safely restore the scroll position. But if if you're just using React Router and Create React App and and you don't have a data cache and you click the back button, it's probably gonna be a spinner at the top and there is no overflow scroll on the body. And so, we have nowhere to- there's nothing for us to do.

[00:19:20] Michael Jackson: Yeah, yeah, yeah. Uh, another another really great example. Sorry, before we move on, I know I know you've got a ton of questions, Michael. But another really great example of this is like our integration on the backend with various backends, right? So, before we could say here's how you render a React Router app if your server is an Express server. Mm. Right? Here's how you do it. Here's a doc page on how you do it, right? Um, in, but now with Remix, what we can say is, you know what, here's uh Remix run Express package. Um, just go ahead and and drop that in, and that's gonna take care of doing all the server rendering for you. You know, or, or like here's a, here's an Express middleware, for example, right? Oh, or, or, or if you're deploying, you're deploying to, uh, Lambda, well, here's a, here's a, you know, an adapter for deploying a Remix app on, on AWS Lambda. So, you know, it's, it gets us, it really gives us the opportunity to get out of that, that place where, you know, we're just like advising you on how to do it and say, here, here, go do it. And to just say, here, we, you know what, we're gonna take on this responsibility. We're gonna have opinions about it. Yeah. And we're gonna do it for you and we're gonna manage your data loading and and so we can do all this other stuff for you. We can help you a lot more.

[00:20:39] Michael Chan: Yeah.

[00:20:39] Ryan Florence: Focus management, scroll position, data caching. Uh there's there's just so much we can do when we own.

[00:20:45] Michael Chan: Yeah.

[00:20:46] Michael Jackson: Deploying redirects and you know refreshing and managing transitions between pages and things. There's just so much.

[00:20:53] Ryan Florence: 404 status codes, 301 redirects.

[00:20:55] Michael Chan: Yeah, yeah, yeah. Okay, well, I wanna I wanna dive into some of the more like technical pieces and like how it connects to backends. Um but I wanna clarify something that I think is is important. Ryan, you and I have talked about this a little bit. But something that's so important about really marrying the the the front end and the back end experience in this way is, you know, you you talk about being able to like manage focus, um, you know, focus when you you you go back and you're navigating around your app. Which is super important. But there's also this um accessibility piece to all of this, right? Where, you know, Because we have moved so much into like dynamic applications, there's so much that we can do by keeping all of that information on the page and like not making people have to like re-navigate like an entirely new page just because one thing, like a comment changed, right? Or, you know, now a menu is open or whatever. Having these like dynamic things on the client is super important for For a lot of experiences that aren't just kind of like, oh, I clicked this thing and now- like for for people who don't have like the visual experience of the web, who can like really quickly see these things changed. And having that dynamic web and like solving these problems is is really more than just like- what is it? It's more than just like, hey, you could have like just done this as as HTML, right? Um because like those things like alerts and these things that happen that are like like these these toast menus, these things are really valuable and they didn't really exist in a really good way before.

[00:22:32] Ryan Florence: Yeah.

[00:22:32] Michael Chan: I guess that's like it's in response to like- I I I just want to talk for a minute about kind of that notion that you brought up of like people saying like, oh, well, you know, we we solved this in Rails like, you know, 10 years ago with, you know, with Turbolinks. Um, but like, but not really. And I know that, you know, as someone who has been kind of at the forefront of of accessible components in React and like really driving that through, like not just in a theoretical way, but like in practice with components. Um like how do you feel about like kind of like that mentality? Like when we've come so far in the other direction to actually provide really great experiences for more users?

[00:23:12] Ryan Florence: Yeah. So for for example, um if you're using— uh one of the most common things to do, and this is what Turbolinks does. Well, I don't know if it's Turbolinks, but I know that Basecamp does it as I've of goofed around in Basecamp. Um, I've looked at the code in Next.js. Um, and I've attempted to solve this in Reach Router a couple years ago and and couldn't because I didn't own enough of of the stack. Um, but this focus management idea in your routes, what what Next.js does and what uh Basecamp, which I assume is probably Turbolinks, is when you navigate somewhere- again, the the whole point is to like avoid a whole bunch of requests to the server, right? Mm-hmm. We don't want to reload the whole page. 'Cause we don't wanna parse all that JavaScript again, just all this all this junk. It's really nice to just change what the user's already looking at. Um, so what they'll do is they'll just move the focus to the body. They'll just whatever, if something was focused and now it's not anymore, someone clicked a link, okay, just move move the focus up to the very top of the page. And if you're using an assistive device like a screen reader, um, it it doesn't, like, Nothing happens. You don't hear anything. There's not a noise. There's not text. You just kind of sit there and you can hit like a keystroke to like basically like like a who am I, like where am I, and then it'll be like, you're currently currently on the document, blah, blah, blah, blah, blah. And uh and now now they got to navigate through the whole page again, which most of the time you'll have a skip links at the top of the page and then it can jump you down to the main nav. But even then, the main nav is not really where you want- well, sorry, it'll it'll jump you to the content, but like-

[00:24:44] Michael Chan: Yeah.

[00:24:44] Ryan Florence: Most UI is nested. And this this is like this is the the big idea that we got from Ember with React Router years ago, is that most UI is nested. You have these layouts inside of layouts inside of layouts. Most apps go 3 levels deep, um sometimes 4 or 5. Top nav, left nav, center.

[00:25:01] Michael Chan: Yep.

[00:25:02] Ryan Florence: And then even in the center, sometimes you have another left nav or something like that. Um so with with moving a lot of our code to the client or or at least thinking about our apps as like a client-side app instead of just a big document. When you click a link, and with React Router and Remix, we can know, hey, well, it's only this layout that changes. We we don't we don't need to worry about the top nav or the left nav or the second left nav. We know we know that it's just this little— it's the user profile that you're looking at. Maybe you got a list of users on the left, global nav at the top, click a user, now you're looking at that user. We can know that's the only piece of the page that changed. So let's go move focus inside of, um, like a— uh, there's various ways to do it. Marcy Sutton has done a lot of research on this. And uh, one of the best ways to do it is kind of have like a a skip nav inside of there and maybe like a little, um, maybe maybe a little uh nav section that's like, um, has a couple of links, like go back to where you were, um, or go down to the content of where we're at.

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

[00:26:06] Ryan Florence: So, you click a link for the user, you get moved to this like little mini-nav thing that's like, hey, go back, or like, or here's the page you're on, here, click this to now go go read it. Um, and and you just can't do that um with the old tech. Without like without JavaScript in the front end doing stuff. Like you can't you can't make that experience really great. Um, now some people might be like, oh, well, you don't really need to optimize that. People using screen readers are good at navigating a page. But um to me, I'm like, but I can. Like we we we could make this— it's it's kind of hard right now, but we can do it. And to me, that's a worthwhile goal goal to uh be able to move them around the page uh without them having to screw around trying to find what changed.

[00:26:49] Michael Chan: Yeah. Well, and this is one of the areas where where mobile devices, you know, if you're using the the default elements, you know, from from Apple's like library or even like Android's library, Like this experience is a lot better on those platforms. And it's kind of one of those areas where it's like the the web shouldn't be crappier just because like we have we use older technologies, right? Like if we can make it better, it'd be nice if we could make it more dynamic and have those experiences have that same level of like comfort for all users.

[00:27:20] Ryan Florence: Yeah.

[00:27:21] Michael Chan: Than than they do, you know, by default with just like sending HTML down the wire every time.

[00:27:26] Michael Jackson: Yeah, I was, I was actually just thinking about Suspense earlier today in that same vein, you know. Um, Suspense itself seems kind of gratuitous, I'm sure, to a lot of people who are like, yeah, whatever, the, the image loaded and then the page kind of- the layout changed, who cares? It's the web, it's janky, like we're, we're used to it, it's fine, you know. But just, just because that's the way things are doesn't mean-

[00:27:50] Ryan Florence: It only had 8 different layout shifts. That's not a big deal.

[00:27:53] Michael Jackson: Absolutely. I was I was trying to actually— I was describing um situation to a friend of mine the other day, and I was like, you know, how the web is kind of janky? And she's like, you know, you're right, it is. You know, like, that's the thing. And and she wasn't she's not a developer, but you know, and she's like, you know, and and I was like, yeah, that's why mobile apps, like, they're so much faster because you download these, you know, 50-meg bundles, uh, you know, when you install the app, and then everything's installed. So like, they don't do requests and- Yeah. Anyway.

[00:28:23] Michael Chan: Well, and those 50 meg bundles sit on top of, you know, whatever UI and- Yeah, exactly. It's already built into it. Already.

[00:28:30] Michael Jackson: Exactly. Yeah, absolutely. So, uh, so yeah, anyway, just to to go back to your point, Ryan, and the point that you were making too, Michael, is is just because, uh, just because we've always- just because it's always been that way doesn't mean it always has to be that way, right? We can do a lot better.

[00:28:45] Ryan Florence: And there there's stuff in Remix, uh, that like We couldn't have done without Suspense. Like, yeah, yeah, after goofing around for a little while, I was like, okay, I know how to- I know how to do this now.

[00:28:56] Michael Chan: Yeah,

[00:28:58] Michael Jackson: I really feel like, um, I don't know, there's, there's been some kind of sentiment in the React community lately, and, and Sunil, who is a man that I love and respect and admire, and I was in the room when you did the podcast with him last year, Michael, at React Conf, kind of expressed the sentiment that I've felt as well and that Ryan has expressed to me as well, which is like, oh, like, I'm I'm I'm just not as excited as I used to be about it, you know? Like, why haven't we gone further? Why haven't we gone further than than we are now? And uh, I mean, how long have they been talking about Suspense now? For over- has it been over-

[00:29:31] Michael Chan: 2 and a half years, I think.

[00:29:32] Michael Jackson: Yeah, it's been a while, right?

[00:29:33] Ryan Florence: I mean, we got we got hints of it. They were starting to work on it when we built React Router v4, which is like forever ago. Yeah.

[00:29:40] Michael Jackson: Yeah. And and and and the but the truth is, it takes time for this for this stuff to pan out, you know, it takes time. But um but I really feel like Suspense is a significant enough uh shift away from how we've been doing things before. Like Ryan said, we we couldn't have done— we we Remix really wouldn't even be that exciting, uh you know, with it without it. Uh

[00:30:06] Michael Chan: yeah.

[00:30:07] Michael Jackson: So I I really feel like- Yeah. It's like a new React. It's like a React V- like Hooks was like V2 and Suspense is like V3. Um, it's, it's, it really is going to change things. It's gonna change the way we think about how we write our apps and, and just make these nice experiences. I can't wait until it's polished and enough to, you know, for real people to start shipping it in real apps and taking advantage of it instead of being like this experimental thing.

[00:30:35] Ryan Florence: And a lot of it gets abstracted away in Remix too. So it's not like you're gonna be like goofing around with Suspense all the time in Remix. It's like, we use it to implement all this great stuff. Now you just get to like, you just get to say what your app should be, where your data comes from, and like-

[00:30:48] Michael Jackson: You just get the benefit from it. You're gonna you're gonna have a link and you're gonna say, you know what, when I click on this link, uh I'm willing to wait, you know, 500 milliseconds for the uh for the new stuff to resolve before we start the transition. You know, I mean, having having that kind of an API at that at that level, that's the right spot where you want to meet the developer and say, hey, um, you want to offer a little bit nicer experience to your user here because you know that it's gonna take some time to fetch the data or whatever for the preload function for that route. Like if you can meet them right there, then that's the point where it becomes easy for the developer to create a much cooler experience than they would have otherwise.

[00:31:29] Michael Chan: Yeah, and I remember we talked about this a little bit in our episode, Michael, um I think it was 85, uh maybe. So it was like about 10 weeks ago. And where we talked about how you were really starting to come around to the the language that Facebook's been using of of of realizing, yeah, like in React Router, we actually are able to let people use Suspense without having to personally use Suspense. Like as as the React Router author, I'm able to like provide a better experience, use these APIs. And not have to expose really anything to to them. What does it look like to expose those configuration options to people? Like how long they're willing to wait for certain transitions and whatnot um in Remix?

[00:32:10] Ryan Florence: Well, that specific question is rough.

[00:32:12] Michael Jackson: Yeah, well, we're we're still working it out. But like like one of the one of the things, you know, that I just mentioned was like, you know, a link, right? You might— and I don't know what the exact API is, right? But you've got a link to a page which indicates, okay, they can click here and they can navigate. Or, or you've got our navigate function in v6. We've got this hook called useNavigate, um, and, and that's how you can programmatically navigate when somebody submits a form or something like that. Um, and you can say, uh, for example, you know, how long you're willing to wait for that navigation, or you can just, you know, configure it, um, um, up top and say, you know, globally we're willing to wait, you know, on, on, in general we're willing to wait up to seconds for data to load or whatever before we actually start transitioning. Um, there's another there's another hook in v6 that we've got called useLocationPending. Mm-hmm. Right? So imagine you um imagine the timeout, uh you know, the timeout's over, we've transitioned to the new page. Um, you can use that hook to say, um, you know, are are we are we still waiting for the for the location to change? Like, are we still waiting for the data to load? Yes? Okay. Well, then we can, you know, show a spinner, right? So, so instead of having these like, you know, the, the, the, the view that's showing the spinner, um, shouldn't really care, you know, about like the, you know, the data, the loading state, or, or sorry, the, the, um, you know, the specific state that you're loading from the server. All it, all it cares about is, you know, all it needs is like this boolean, like, should I show the spinner or not, basically. And so we've got a couple of places for for you to hook in there. And and so you know you can throw in a Suspense fallback um component anywhere you want, or you can use this hook anywhere you want to you know decide to uh you know whether or not you're gonna show some loading indicators. Um but it's it's not like you're gonna have to be the one who's gonna say you know useTransition, um you know startTransition, right? You're you're that's not. Your job, we can build that into the router and we can build that into Remix for you.

[00:34:23] Ryan Florence: Interesting. I want to add to that a little bit. Imagine this kind of user workflow, right? I'm looking at a list and it's one of those master details. The list on the left, the content is on the right. And you click on a user. We might want to wait 2 seconds, right?

[00:34:39] Michael Chan: Yeah.

[00:34:40] Ryan Florence: Or maybe we want to wait 5 seconds for that data. And if uh But but you don't want to just sit there with like a a silent, non-responsive app for those 5 seconds on the old screen. Like if I if I click on that user, I want I want some feedback that the app is thinking.

[00:34:57] Michael Chan: Yeah.

[00:34:58] Ryan Florence: And so, like Michael was talking about with the with the useLocationPending, I can now say, okay, in my user list, the link that you just clicked, uh I want to show a spinner inside of that link. Not the whole page, but just inside that link I clicked. Just like indicate like, hey, I'm I'm thinking about this. And maybe I'll just use CSS to delay that by like 500 milliseconds.

[00:35:17] Michael Chan: Mm-hmm.

[00:35:18] Ryan Florence: So I click the user link, 500 milliseconds go by. Now I get a little spinner just on the user link. But I'm still looking at the general page I was looking at before. Now I get uh now I can kind of hang out for— uh if it's been 2 seconds and all the data loads, then boom, it transitions to the to the new screen. But if it's been 5 seconds, which Michael was talking about, we can like put on the link like link, wait 5,000 milliseconds or whatever the API ends up being. Sure. Now, instead of just a little spinner on our link, we get like um we get like a big spinner for the whole app. Or maybe there are two routes. We got like some nested routes here. And so, what we're gonna do is we're gonna say, well, you know what, we already have some data for the page. And maybe it's the majority of the data. But but maybe it's just the comments on this user profile or something that we don't have yet. And so, it makes sense to transition to that page and show the main content while we throw a spinner up on the next page for the data we're waiting for. So, so it's basically like saying, hey, wait 5,000 milliseconds for everything. Um, but if it's been 5,000 and we've got some stuff, let's show what we've got right now.

[00:36:20] Michael Chan: Yeah, yeah, yeah. So, it sounds it sounds like you're not necessarily opting people out of using those APIs, but uh you're making it so that like this framework's making it so that you don't have to think about them. You can kind of just like run and gun, build your application, and then maybe like fine-tune those experiences as you need a little bit later.

[00:36:37] Ryan Florence: Yeah, with the Suspense component, the SuspenseList component, you'll use those. Um, you'll use locationPending. So that's how you know to put the spinner up on the link. Um, so so we get to tell you like, hey, we are transitioning, but we haven't yet. And so now you can put spinners wherever you want. And then the rest is just normal, the Suspense component stuff and the composition there. But what's cool is that we have these nested routes. Um, and so that allows uh you to control more where spinners go up. You could just have one big spinner on the whole app, or you can say, you know what, for this layout, um, or this layout, let's put a spinner here. So so you could see the main profile, maybe while we're fetching the list, a spinner goes up. Or maybe the list will show up, but then we got a spinner on the profile, because those are those are our nested routes.

[00:37:20] Michael Chan: Yeah, yeah, yeah. That sounds great. I I I always get really frustrated when people feel like they have to reinvent the world, right? To to you know, because you're building this framework, there may be like a little bit of like a a pull to like own the whole problem. Like own all of the language, right? Um, but I I appreciate when framework authors have the the restraint to let things that are good enough just be the thing that's used. And like allow like Googleability of that thing, right? Like you you can now have like the whole world as like a resource for like how to like kind of move your Suspense and error boundaries around to like make make the UI exactly how you want it to be instead of just what you've written.

[00:38:01] Ryan Florence: Yeah, and that's that's why we couldn't have done this without Suspense. That's why we're so excited about it. You mix you mix Suspense and the fallbacks with Suspense, uh with the composition, with nested routes, um and then that useLocationPending thing, all all those pieces together are are gonna allow us to create really great loading experiences.

[00:38:20] Michael Chan: Yeah, yeah. Now, Michael, I wanted to go back to something that you had started talking about, but uh but I kind of cut you off to finish off this part of it. Um, I want to talk about the backends. And I feel like you're like such a good person to really like be thinking about this because you spent— like is it 4 years now on Unpackage?

[00:38:40] Michael Jackson: I think we're closing in on 6. Closing

[00:38:41] Michael Chan: in on 4? 6? No. Has it been that long?

[00:38:46] Michael Jackson: Wait, no, no, no, no, no, no, no, sorry. We're coming up on 5. You know, we're coming up on 5. It was it was November 2015. We're coming up on 5.

[00:38:52] Michael Chan: Oh my gosh. Time is going too fast. Okay.

[00:38:55] Michael Jackson: Yeah.

[00:38:56] Michael Chan: Um, so I'm really kind of curious, like from your perspective, like what you've been infusing from what you've learned um from Unpackage um to really build out the kind of like backend connection pieces of of Remix. You you mentioned kind of having these these pre-configured ways to build for platforms, you know, whether it be like a Lambda or, you know, Google Cloud Functions, et cetera.

[00:39:19] Michael Jackson: Yeah, for sure. Yeah. So, so there's one, there's one thing that I've been, I've been kind of snarky about it, honestly.

[00:39:29] Ryan Florence: I knew you were gonna go there.

[00:39:30] Michael Chan: No, no.

[00:39:31] Michael Jackson: On Twitter. I've been kind of snarky about it. And I, thing is, I'm really not that snarky of a person. Like I just, I'm, I'm a, I'm a nice guy. So I just want people listening to the podcast to know that I'm You know, I'm not that snarky really, but we we need to talk about HTTP caching because there is like, there is some weird stuff going around. And I'm like, I I thought, I thought here we were, I thought this was a solved problem. Like, you know, HTTP as a protocol is, um, it's a stateless protocol. And so, you know, you don't, you don't have these you know, live open connections uh to servers all the time. Of course, you have WebSockets now, but but you know, typically you just you make the request, you get the response, that's it. And so, you know, we've gotten good. I mean, it's 30 years old now, more than that. Um, you know, we've gotten good at having, you know, uh proxies for HTTP and and and caching servers, you know, middle servers and and and CDNs. That that manage caching, right? And so there's some pretty- and that's what helps make things really, really fast, right? So even if you have an origin server that's located in Des Moines, Iowa, you know, somebody browsing your site in, you know, Jakarta can actually load your site pretty quickly because you're, you know, you put your origin server behind a CDN like Cloudflare or something, and they have, uh, you know, they have 166 data centers all over the world, right? And and and it's something that we've been doing for years now, right? Akamai, uh CloudFront uh from from Amazon, uh Cloudflare, obviously, they're they're you know uh Fastly. There are lots and lots of different CDNs, and and anybody who's building a large uh uh website, enterprise-scale website, uh is familiar with this and is using this technique to optimize delivery of their sites around the world. And so that's something that I had to learn, um, you know, from experience when I was building Unpackage. Um, Unpackage, for anybody who's not familiar, is a reverse proxy for uh files that are on npm. So, uh, anything that somebody publishes to npm, you can get it over HTTP, and that's basically it. Um, and when I first started Unpackage, it was, it was a Heroku app, you know, it's just this app running on Heroku and who knows where. Uh data center, um on a on a dyno, whatever that is. Um and uh-

[00:42:05] Ryan Florence: Is that a new TypeScript?

[00:42:07] Michael Chan: Yeah.

[00:42:09] Michael Jackson: Oh yeah, right. Dino, dyno.

[00:42:11] Ryan Florence: Oh, that's good.

[00:42:12] Michael Jackson: I mix them up. I don't know. Um so so anyways, this is this little app running on this little dyno somewhere and it's serving, you know, millions of people all over the world. Well, how's it doing that? Gee, I wonder. Um it's sitting behind a a CDN, right? And it and it and it issues these really aggressive caching headers. So for example, you know, if you request, uh, react-16.8.0/index.js, um, we can, you know, Unpackage can know, okay, that file is, is pretty much never gonna change because once you publish a package to npm, the contents of that package never change. You can't override a previously published version for obvious reasons. Um, and so we're just gonna say that file is good to be cached for a year or more. Um, never, never gonna, you know, if once you get this file, you can keep it for as long as you want.

[00:43:00] Ryan Florence: And a year is the limit, right, with HTTP That's why-

[00:43:03] Michael Jackson: Yeah, yeah, yeah. It's

[00:43:04] Ryan Florence: the only way to say forever.

[00:43:05] Michael Jackson: And so, it gets- so, it gets, you know, cached in data centers all over the world. And then uh pretty soon, requests for that asset stop hitting the origin server. They just stop. They just don't hit the origin server anymore because they're cached in all the data centers around the world. And so, um so, I've worked on this for quite a while in Unpackage. Unpackage actually has uh a 99-plus percent cache hit rate. That means, yeah, obviously the vast majority of the time that you're hitting Unpackage for a file, you are getting it from one of the 166 data centers spread out around the world, right? And so there's, you know, so so HTTP caching, it works well. Um, and and there's been kind of like this movement, I feel like, um, even among people who are like very, very with it uh in the web community to say, um everything needs to be static, right? Everything must be static. Everything must be HTML, CSS, JavaScript, static, pre-generate as much as you can. Um and and that's nice and that's good, but but you lose the ability then to vary the response based on who's doing the requesting. Right? So, you know, again, these- anybody who's building large websites nowadays has a a login, has a user login, and those users have different things that they can see based on who they are, different permissions. And so if if you're pre-generating this HTML page and you're supposed to serve that exact same HTML page to, you know, hundreds, potentially thousands, hundreds of thousands of different users, um, you can't really include any unique identifying information in that HTML page. And, and excuse me for explaining it like you're all 5, but this is like, this is basic like- Yeah. —stuff, right? This is basic HTTP HTML stuff. So what you end up doing is in the pre-generation of that HTML page, you can't include any personally identifying information. Um, and so it ends up being kind of more or less like what we were talking about earlier, like a shell. Maybe you've got like the nav in there, you've got like your footer or whatever.

[00:45:19] Michael Chan: It's just a template, basically.

[00:45:20] Michael Jackson: Yeah, exactly. It's just a template, just an HTML document that's not really useful. And then so so you can pre-generate that, but then anything that's actually useful for that user when they load that HTML page, uh they're gonna have to load that in in another request, right? And uh and and and so it's this it's this you know this kind of like back and forth right now, I feel like, in the, in the React framework space between static site generators and, and sites that are full-on server rendered. Mm-hmm. Um, and, and Ryan and I are, are kind of of the, of the opinion that, you know, as long as you've got your app behind a CDN anyway, um, you can just server render the thing, which means you get all the flexibility of, um, of a server-rendered app, right? You don't have to like jump through the holes or jump through the hoops that you have to in order to try and pre-generate things. Mm-hmm. Um, so your build time is, is zero. Uh, it's, well, I mean, you have to build to build your bundles, but like, you don't, you're not like pre-generating a whole bunch of HTML pages. So it's, so it's a lot lower, right? We don't need like, we don't need like a, a, a server farm to like build your, you know, thousand, hundreds of thousands of static HTML pages. Um, and and and you increase your flexibility and you're not slow because you set the right caching headers and and your page serves just as quickly. I mean, the truth is, even if you are using a static site generator, you're putting it behind a CDN like CloudFront or Cloudflare or whatever. Um, and and so as far as your statically generated app, which has a shell of an HTML file, And my statically gen- or my server-rendered app that has a a full-on HTML file with a with a Vary header that's based on, you know, that user ID, that session ID. Um, you know, what basically what that means is I can serve a full HTML page, and and the only time I suffer uh any sort of penalty is on the very first request. Uh, when I go back to the origin server to actually generate the HTML page. Um, every other request is is is just as fast, right? Assuming we're both using the same CDN. Um, and and and and and we're not, you know, forcing the user to to make additional requests for the data uh once the page loads. And so this is this is actually one of the one of the uh kind of really cool things um that we're doing with Remix is Remix will- so we've talked about server rendering. Remix will actually server render your app uh in development too. Which is which is kind of a tricky kind of a tricky thing to do. So it'll server render it in production, but it'll server render it in development too so that you can see at any point when you're developing in Remix, you can click the refresh button and you can see exactly what the server will send uh to to you know to the browser if if the user was to land on that specific uh page. And the whole thing is gonna be server rendered. Um and and so we're we're pretty confident that this is the way to go just because of uh well just because of all the experience that we've had with you know serving large-scale uh server rendered apps. I mean it's it's it's a model that's been around, like I said, kind of at the beginning, like. We're taking ideas from Rails, we're taking ideas from PHP. These are not new ideas. You know, the ideas behind HTTP caching are not new ideas, um, and they're very, very robust. Yeah. And and and they've— you know, it's what we've built on up to this point. So, um, we're we're very confident that we can get, you know, really great performance out of these Remix apps, but then also, um, also preserve the flexibility that you get when you need to do things, you know, at runtime because you need session data in order to generate the page.

[00:49:23] Ryan Florence: And so so what this means in like a practical perspective, uh like a like a like like an example, um imagine instead of having 3,000 Markdown files that when you go to publish your website, you've gotta build the HTML for all 3,000 of those Markdown files. And if you have a successful content site, you're a newspaper or something, you're gonna have a lot of of data. And so instead of having all those Markdown files, you got to build all of them um in order to ship the page. Imagine all that Markdown just lives in a database, uh you know, like WordPress.

[00:49:56] Michael Jackson: These are revolutionary ideas here.

[00:50:00] Ryan Florence: It doesn't need to be code or a file. It can live in a database. And so now you don't have to deploy your whole website In order to add a new page, all you have to do is add a record to your database. And then when someone hits that URL- I mean, again, this is like- I'm explaining this like it's this cool, amazing idea, but this is how websites work. And like this is how the web has always worked. Someone hits the URL, uh Remix has these loaders that only run on the server. It's gonna go to your database. Uh you get to do this part yourself. Go to your database, pull down your markdown. Bring in um Remark or whatever you want to use in uh in in Node, convert the thing to HTML, send that HTML uh down to the React app, and then uh set the innerHTML of a div. And now you've got your like you've got your Markdown post. Um and then mix that with what Michael's talking about. And if it's all static, there it doesn't vary on the user ID. Um

[00:50:57] Michael Jackson: so- And you didn't install any plugins to do that either, right?

[00:51:02] Ryan Florence: Yeah, yeah.

[00:51:03] Michael Jackson: There was no like Remix whatever Firebase plug, like, you know.

[00:51:08] Ryan Florence: Yeah, you got to just copy and paste this markdown. Um, or you could just use GitHub's markdown API and send the markdown to them and they'll give you a response, too. Um, anyway, so you just send that text down. And now, the if it's truly static, um, you don't have a Vary header. And so, the CDN, after the first person goes to that page, and that could be you, right? You just published it. Now you go hit reload before you tweet it out. Now the thing is cached. You don't redeploy your website. You don't go through a build. You don't do any of that stuff. Your function gets called one time and then it's cached through HTTP. The the very the very same. If it's if it was a flat file behind the cache or it was something that got generated from an HTTP request in the first place, everyone else who gets it from the cache, it's the same.

[00:51:53] Michael Chan: Well, I'm kind of curious. So so where does this put like uh headless CMSs, right? Because there's this whole move right now kind of to back- like to create backends for things like, you know, Next and Gatsby and whatnot. And and the whole thing is like you put your content up there and then, you know, there's some type of webhook that like when you put a new post, now it's gonna rebuild your entire site and like redeploy it and whatnot. Like is there still like room for that? Or are we gonna like move back to like like Now you put all your stuff in like Postgres.

[00:52:25] Ryan Florence: I mean, you either you either cache it to a file and then put it on a CDN or you generate it once on your server and put it on a CDN. Uh but but I I want to actually take a step back and say,

[00:52:36] Michael Chan: yeah,

[00:52:36] Ryan Florence: this is not our target market with Remix either. This is just us talking about how it works.

[00:52:41] Michael Chan: Like totally, yeah.

[00:52:42] Ryan Florence: Like uh we we want people to build with Remix. I'm sure they can build something like this. You could you could totally have a CMS backend. And you just talk to the database in your loaders and Remix and generate whatever markup.

[00:52:52] Michael Jackson: Generate your blog or whatever. Yeah.

[00:52:55] Ryan Florence: And that like that that will work and it will be great in Remix. Yeah. Uh but but really what we are thinking more about is the kinds of stuff that we built throughout our careers in web development.

[00:53:05] Michael Chan: Yeah. Um

[00:53:06] Ryan Florence: I worked on a learning management system. Uh it was a Rails app. You do rake routes. There were 2,500 routes. Um that's a that's a lot of it's a lot of UI. Um, everything was behind login pretty much. Some stuff was public, but if you were logged in, it was a little bit different. Um, lots of admin panels, dashboards, um, lots of user-generated content. Um, you know, so so like that's that's what we're thinking about. We're not thinking about making a blog or a newspaper website. We are we are thinking about building um uh a Zillow or a learning management or a Netflix or— Or a Twitter.com. Or a Facebook or a Twitter.

[00:53:47] Michael Jackson: Yeah, which is where I I worked.

[00:53:49] Ryan Florence: A a a sports a sports team management, a Little League a Little League admin panel so parents can log in and see when the kid's game is. Totally. You know, it's yeah, it's it's that kind of stuff. And we want to have all those benefits of server rendering and and caching and and all that kind of stuff. But uh yeah, we just— yeah, we're we're we're we're not worrying so much about the static generation stuff. Of course, we're thinking about the apps that we've built.

[00:54:14] Michael Chan: So that brings up an interesting point. So I I know that in React Router v6, you've you've done a ton of work to really like double down on the dynamism of of React Router. Um and you've added some APIs to be able to like leverage the file system to kind of build your architect your application, right? Can you tell me about how those things are kind of coming together to like inform Remix and inform the way that you'll build applications with Remix?

[00:54:42] Michael Jackson: Yeah, yeah. Sorry, uh, I feel like I jumped in front of Ryan.

[00:54:46] Ryan Florence: No, no, go. I I finished. It's your turn. Tag.

[00:54:49] Michael Jackson: Oh, it's my turn. Tag. Ding. Um, one of the things that we talked about last time- so we've talked about a lot about file system routing. I just wanted to make it clear that like that's like we'll have a pro- we have a programmatic, uh, way to do routing as well, right? So if you don't like the file system thing, no big deal. Uh you can you can build your build your routes with a function.

[00:55:09] Ryan Florence: It looks pretty much like an Ember route config.

[00:55:12] Michael Jackson: Yeah, very similar.

[00:55:15] Ryan Florence: Um, well, I don't know, actually, a 5-year-old Ember route config. Maybe it's different now.

[00:55:20] Michael Jackson: May have changed. Um, but but for so for example, one of the things that React Router does, um, and one of the features in v6 that's really, really cool is this automatic route ranking algorithm, right? So one of the big problems with v4 and v5 and React Router is If you put your routes in the wrong order, then some routes are unreachable. Um, and we talked about that uh in the last podcast that we did, and it'll be familiar with anybody who's uh who's used V4 and V5. Um, and it's, you know, you have you have exact control using the Switch component over which order your routes are in, but it it really is just dumb, kind of like a switch statement. It just goes through your routes in order. Matches the very first one and renders that, or the first one that matches it renders. Um, the Routes component in v6 is actually a lot smarter. Um, so it'll, it'll take your routes and it'll, it'll actually look at your routes, look at the route tree deeply, right? And it will figure out, okay, based on the current URL, which one of these routes is the best candidate to match the current URL, which takes a ton of- Intellectual like strain off of the developer, right? They don't have to think as hard about, oh, okay, why isn't my app working? Oh, because I put this one in the wrong order. The router's gonna figure it out for them, right? Well, um, so, you know, trans- And that's

[00:56:41] Ryan Florence: knowable. Like most times people think like, oh, this is like CSS selector specificity and like that's a that's a disaster. It's like, no, this like we know which one you meant. Whichever one's the longest, whichever one's the most static, everyone has the fewest dynamic segments.

[00:56:55] Michael Chan: I think we talked about it last time. It's a little bit more like pattern matching, right? Where it's like, like how how many things are are are specified here? And like we're gonna use the one that like matches the best.

[00:57:06] Ryan Florence: So sorry for jumping in there, Michael.

[00:57:08] Michael Jackson: No, not at all. Well, so so you talked about, you know, how does how are the things we're doing in in the router influencing Remix? Well, so Remix comes along and says, hey, I want to do file system routing. Well, so on on the file system, right, the the way that your files are ordered is just by name. Right, so you might have a.js and b.js, and no matter, you know, you could try and put an underscore in front of the other one, you know, b to try and get it to sort before a and do weird things like that.

[00:57:34] Ryan Florence: And then 2 underscores and then 3 underscores.

[00:57:36] Michael Jackson: Right, right. So you can, you can try and, and make it the way, you know, just perfectly how you want it, um, but that would be a huge pain, right? You just want to name the files naturally, uh, but then you also want them to match Uh, in a smart way, right? And so we've got uh syntax in the file name for, for a dynamic segment, um, and then, uh, and then we've, we've got dots. We'll use dots in the file name to indicate, um, you know, nested URLs. And so we've got this, this, uh, you know, and this is all just convention, right, for how you name your file. Name your file like this and, and we'll nest the routes like this. Well, it, it turns out that when we're looping over the file system, you know, we're just generating routes from these file names based on these file names, um you know we don't have to order them, right? It's it's really cool. We can just loop over the file names, generate a bunch of routes. Here you go, React Router. And React Router is gonna say, thank you very much. I know, uh you know I've I've I've already got the smarts to be able to sort these things and match the right ones.

[00:58:36] Ryan Florence: So you could have like a me.js. So you go to like users/me. We know that one's static. So we're gonna put that one above like users/ Right? Like, which one did I really mean? I don't want to fetch a user with an ID of me. I want to show the static route of me. Um, and so, yeah, with this ranking algorithm, you can do that kind of thing.

[00:58:56] Michael Chan: Nice.

[00:58:57] Michael Jackson: Right. Um, so there so there was that. Um, another API that made it into v6 is the route preload API. Um, which quite honestly, uh, I think I think, um, is- it's so- I don't know how to say this. It's, um, it's something that I I don't think is- well, Suspense is new. And so I think people who are trying to build stuff on top of Suspense are still kind of like working out exactly what these APIs should look like. Sure. So we've got this route preload function that is really just- it's really just a function. We don't care about the return value. We don't care about You know, you're not gonna return a promise or anything. We're just, it's just a, it's like a notification that we're gonna call on a route. If you have, if a route has a preload function, we're just gonna call that when it's time for that route, when we've matched that route, basically. It's like a notification, like, hey, congratulations, we are about to render you. Right. And so it's, it's the opportunity for that route to, to preload. That's why it's called preload. So it can go and initiate the fetch for some data and, and can go ahead and cache it. But but we didn't really have, I think, a firm grasp on what that looked like or what that meant until we started building Remix. Because then it was like, okay, so, um, you know, what like what's gonna happen after the preload? Where does the data go? And well, it goes into the Remix cache. Well, so then how are we gonna retrieve it? Well, we can have a thing called useRouteData, which is a hook that can go and grab the data out of the cache. Oh, okay. So, so then the preload function really just needs to be called with the current params and the current location, and that's it, right? Right. So, you know, building something higher level on top of React Router actually helped us to understand better, um, the constraints that we were working with, you know.

[01:00:51] Ryan Florence: And here's what's- here's what I think is really cool about that. Uh, I keep coming back to nested routes, but, um, in in React Router you can have 3 routes that are all 3 nested layouts. And so instead of just saying, here's the URL, what's the data for this page? You get 3 routes that all get to participate in that, that get to say, hey, uh I'm I'm the user route, I'm the users route, and I am the home route. Um and all 3 of those routes match. And so we call preload on all 3 of those. Yep. And and you see sometimes when Facebook gets up and talks about things at conferences with GraphQL, how they have these like um these GraphQL um uh fragments that then they like combine all those fragments together and then create like an optimized uh query that then they send to the to the database or to their to their server. And uh I've always kind of looked at that like, yeah, but how do you know, where do you get all those fragments from?

[01:01:45] Michael Jackson: Yeah.

[01:01:45] Ryan Florence: Like how do you know which part of the page is gonna render?

[01:01:48] Michael Jackson: Well, just ignore that part. We've got the fragment. Let's move on.

[01:01:50] Ryan Florence: Um and and so with with nested routes, I mean, most, I I said this in one of our newsletters, When you look at data dependencies for a web app, they are almost always coupled to your routes. I'm at this route, what data do I need? I'm at this route, what data do I need? And so, since React Router is also coupled to your layouts, we kind of get like a little cheat code. It's like it's like uh some people when they server render in React, they like they they render over and over and over again and just collect up all the promises. Like let's render, okay, which promises do we need? Those ones landed, okay, keep rendering. Okay, now what do we need? Okay, render, try it again. So you render the thing 5 times, your whole app 5 times and collect all these promises. I think Apollo works this way. Yeah. And then once you've got it all, okay, now we can go. But with with nested routes, we get this cheat code where we got to say, you know what, these 4 routes, these 2 routes matched, and that's where your data dependency lives anyway. So we we kind of know indirectly what's going to render before we even have to render it. And so, with Remix and uh well and the route preload can do this, too. Uh we get to tell you, hey, these 3 are going to preload. You can optimize whatever data you want here. And in Remix, what uh what we're gonna be doing, it's it's really cool, is um when all of those routes match, we go to Remix to ask for the data. And Remix on the server also knows your routes. And so, it can say, okay, well, you just told me you're on this page. You want to go to this next page. And the server's smart enough to say routes A and B are still matching. So I don't need to send you the data for that. And I don't even need to go fetch it on the server for that. I only need to fetch the data for C and send that down. And that stuff is just gonna happen automatically. App code isn't even gonna have to think about like, oh, which routes changed, which ones didn't, what data do I really need to optimize to go fetch? Remix can can actually just do that part for you.

[01:03:44] Michael Chan: Wild. Wild.

[01:03:45] Michael Jackson: One of the things that's so cool about Ryan and I getting the chance to build this together is we've we've seriously spent 6 years like thinking about building, you know, this router. Um, I just went back actually the other day and I looked at the very first commit uh on React Router, which I think was May 2014, um, and it was just Ryan like, you know, noodling around. He's got like this mix-in and like some createClass stuff. And, and, and I looked at that and I was like, you know, it- honestly, a lot of the core ideas like haven't even changed.

[01:04:18] Ryan Florence: That code probably looks more like, uh, the router is today than-

[01:04:23] Michael Jackson: It does, actually. There was a, there was a method on the mix-in called outlet, and I was like, oh look, v6 has an outlet component, you know, like, because we didn't have context back then, so you needed a mix-in. But anyway, um-

[01:04:34] Michael Chan: That's very, uh, Ember-influenced.

[01:04:36] Michael Jackson: Oh, absolutely. Absolutely. We we have never been shy about the fact that we ripped off Ember. We have never uh tried to conceal that fact.

[01:04:44] Ryan Florence: V4 kind of went away from it, but uh V6, we came right back.

[01:04:48] Michael Chan: I mean, they had some good ideas.

[01:04:49] Michael Jackson: Oh, they totally-

[01:04:51] Ryan Florence: Yehuda and Tom will always be like JavaScript and web development and just programmer heroes to me forever. Like super smart guys.

[01:05:01] Michael Jackson: Um, but one of the things I was I was gonna say is, um, It's really cool now that we get the chance, I think, to build Remix because we've been thinking about this stuff for a very, very long time. And at the heart of building a web app is having a good router. You know, some people will think like, oh, well, routing is really just, you take a look at the URL and you call a function. You know, I think I think that's what like the router is in like 99% of of cases, you know, Express's router works a lot like that. Um, I think even like the router in in Reason React works like that. It's it's um it's it's really just kind of like a kind of like a switch case statement, right? Um, but when we start talking about things like this, right, we start talking about the fact that, okay, so when you render a React Router app, because the routes are because the routes are nested, we actually know um all the different levels, uh the components that are going to render on the page. And we and each of them, by the way, has this associated preload function. So we're able to Um, you know, just call all of those and and render the whole thing in one shot without sort of like re-rendering and re-rendering and re-rendering and guessing and trying gathering all the promises as we go, not knowing, you know, how deep does this UI hierarchy go. Like, if you if you're not a router, you don't know, right? But if but if you are, then you know exactly which routes matched and which ones didn't and whether or not you need to send a 404 or a redirect or whatever. So for us, the opportunity to, I think, work on Remix, it's like, it just segues so nicely from what we've been doing for a long time now.

[01:06:38] Ryan Florence: You just you just reminded me of another cool thing that we can do knowing all that stuff. Is uh let let's say that the server is like, oh, you know what, you got routes A, B, and C. Both B and C are changing, so I'm gonna fetch that data. We don't actually have to wait for all of that data on a route transition in the client. So, we can actually- we can stream that data from the server. And when uh say routes B and C, those are the two that we're fetching. Let's say that C is ready before B. So, B is like the layout that's above C. Um, we can use- you the the app developer can use Suspense to like put little boundaries around like, okay, here's the nav. And if I'm waiting for route B, after 3 seconds, I don't want- like the nav for some reason is a slow response and it always takes forever. But Route C, we get that content like really quick. So we should transition to this quickly. And so when Remix is is fetching that data, we can stream down when C is ready. That'll go down and then React can render the main page and then put a spinner up on the nav. So this is that um render as you fetch idea. Yep. And having these nested routes and then a data abstraction on top with Remix allows us uh to just do that part for you. Um, you just got to put your suspense boundaries in the right spots.

[01:07:53] Michael Chan: This has been episode 99 of React Podcast with Michael Jackson, Ryan Florence, and myself, Chantastic. For links, visit reactpodcast.com/99. Thanks to Infinite Red for supporting this show. If you have a project that's gone off the rails and needs expert help, get Infinite Red on your side. They've been designing, building, and shipping apps for 10 years and want to help you through the hardest parts. They have a sweet deal going right now where if you refer a project, you get $750. Pretty sweet. Get expert help today at reactpodcast.infinite.red. If you like this show, there's a fast, free way to demonstrate your support. Leave us a review on iTunes. It's the best way for you to let me know what 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.