- Podcasts
- CodingCat.dev Podcast
- Code with CodingCat.dev: Remix with Kent C. Dodds
Code with CodingCat.dev: Remix with Kent C. Dodds
CodingCat.dev Podcast
- June 30, 2024
- 1 h 54 min
- Episode 6
About this episodehttps://codingcat.dev/podcast/cwcc-0-6-remix-with-kent-c-dodds
https://codingcat.dev/podcast/cwcc-0-6-remix-with-kent-c-dodds
Transcript
From the publisherThis transcript comes from the podcast’s own feed, shown as the publisher wrote it.
Code with CodingCat.dev: Remix with Kent C. Dodds
Welcome back perfect peeps to code with coding cats. That felt weird, didn't it? It did. It's usually perfect, that dev. It throws me off every week, as you can probably tell. We have Kenzie Dodds with us. Hey, Ken. With the awesome neon remix sign in the background. Yeah, so when he told me I need to put it up here, but. Oh yeah, that would be cool.
It's harder to it's literally just hanging on the hooks that I had already for my lanyards. And so I just like threw it up there. Oh. You're a lanyard keeper. I always wanted to be. They always get shuffled away in my moves though. They're like. Yeah, I, I'm glad that I did. I have every lanyard I've ever for every conference I've ever been to. And so now it's kind of a fun reflection. Yeah.
That's awesome. My son was collecting mine for a long time. I was like, yeah, you can have. This. So we are going to go somewhat fast today because we're kind of try to build something pretty crazy in 90 minutes. And you know, with that said, how how's everybody Friday? First of all, let's say at least do a little intro. We always try to do this.
Brittany how was how was Netlify this week? It is good. I'm trying to get my last July blog post out today so hopefully that's going to go well. It's going great though. How was Apprite? Apprite was good. I'm learning a lot, but also having to put my like PHP brain back on, which has been, you know, 1215 years. So I'm having a little bit of like imposter syndrome, like, Oh my gosh, I don't belong here.
There's like some incredibly smart people working on the back end for all this stuff, so it's pretty cool, but working on some fun apps for tutorials and things like that, which has been super fun. Digging it. That's very cool. How are you Ken? Anything fun this week? Yeah, this week I'm going to Front End Masters next week and teaching two workshops on remix.
And so this week I was working on the tooling around the workshops to make that experience seamless, and that's always fun. Yeah, those front end Masters workshops are a bear, aren't they? Yeah, yeah, scheduling a front and master workshop or or an egghead course is always a good forcing function for producing content for me so. Absolutely.
Cool. Well, without any more ado is obviously. I don't know, it'd be all proper. So probably in another 10 minutes once we have some more people on, we will do the drawing for the five giveaway for level up tutorials. So just supporting our creator community out there. We'll jump out in a bit. But other than that, I think are you guys ready to code? I, I know Brittany's kind of running the show today on the coding side.
So. Sure. Yeah. So Remix is a web framework for building excellent user experiences for the web, a very strong focus on the web platform and using JavaScript to enhance that experience. So progressive enhancement is a big piece of what we're doing at Remix. And yeah, it's built on top of React Router.
So it's, it's basically an evolution of React Router. It brings a whole lot of extra features that React Router hasn't had so far. And in the next week or so, I, I feel like I've been saying that for a while, but really this time probably next week we'll have released React Router version 6.4, I think, or maybe it's 6.5, I can't remember.
The next minor bump of React Router that brings in a lot of the features of Remix. So loaders, error boundaries, actions, forms, fetchers, bunch of stuff. And this is really exciting because it, it means that it's actually very straightforward to migrate an existing React app to Remix if you're using React Router, If you're not using React Router, you're probably using Next and maybe Gatsby.
And those have different migration stories. But, but for React Router apps, which is most React apps in the world, migrating to Remix is actually pretty straightforward, thanks to the fact that it's just built on top of React Router and, and we're bringing lots of the React Router or Remix features to React Router. So I can ask.
So yeah, we have published a pre release of this, which is why we talk about it. We try not to talk about stuff that hasn't shipped yet, but this is technically shipped because we do have a pre release. And so people have taken the pre release and we've got an somebody who's worked on an angular router with remix router and somebody who's worked on Svelte Austin and and Vue and pre act. So yeah, the lots of exciting developments in the future, it's not like we're necessarily hedging our bets because like let's face it, React is still like three times as widely used as the rest of them combined.
But but it's still, it is not everybody wants to use React. And so this gives them a a chance to get these really cool features without having to use React. Yes, thank you. Thanks for talking about that for a minute. Yeah. Another question that I had on Remix is, so from my understanding of it, just briefly like reading through the docs and learning a little bit about it, is that it's kind of this middleware between the server.
So it handles the request from the server back to the client. Is that right? And can you explain that a little bit? Yeah, yeah. So we like to call Remix center stack because it manages the network tab for you. So by that I mean all of the data loading, you write the server code for loading the data. And so everything, the code that you write for getting data is all written on the server.
So you can talk directly to a database or you can make a fetch request or whatever. And you just, you know, you can do your await and whatever normal JavaScript stuff you're going to do in there. And then you return a response, a web fetch response. So you say new response, whatever, or we have some helpers because most of the time you're going to be returning Jason.
And then on the client side in your in your components, which may or may not be a client side because you can be doing server rendering too. But in your component, you use a hook called use loader data. And so Remix is managing getting that data from that server code that you're writing into your component. And so that's why we say we're managing the the network tab and and even more than that, we also manage mutations for you. So you need to make a change to the data. We've got a form component that you can use. And when the user submits a form, we'll take care of serializing that up the same way the browser would and send it to the back end where your action code is waiting to handle that action.
And what's cool is Remix emulates what the browser does. And so your code remains the same whether or not you want to actually have JavaScript in the the client. And so it actually works if the JavaScript fails to load or the user disables their JavaScript or whatever, which of course most people don't do. But, and, and there are reasons that we, sorry, there are reasons that we want JavaScript in the clients. And so we, this is where the progressive enhancement piece comes in and, and, and Remix, when JavaScript does show up in the client, remix will emulate the browser. And so what's really great about that, though, is not that like, oh, well, we're resilient if JavaScript doesn't load, like that's great.
But what's what's really good is the fact that it works without JavaScript is evidence that you don't have to manage state in the client. Because if the app works without any JavaScript, then obviously you don't need state in the client. And so no, no Redux, no Apollo, no Mob X, no React query, none of no context, none of that stuff is is necessary for application state management now. Context can be useful for other things, just not application state management.
Now of course Remix and React Router are using context for what they're doing, but the fact is that you don't have to use context, you don't have to manage any state, and you also only use use effect for like focus management and stuff. So Remix makes the hard parts of React a lot easier, which I really appreciate. Yeah, that is really nice too.
That, that one's interesting. I think that I I'm a little concerned that people are going to start over using that hook. The fact is that useeffect, it helps you uncover problems in your code that you never would have back in the class component days. So like the sorts of problems that you discover in production, not during development.
Useeffect is so frustrating because it reveals all those problems to you during development and yeah, when they happen in production, you just don't realize that there was something you could have used in development that that would have helped you avoid those problems. I've got a blog post about this on Epic react dot dev slash articles.
It's about, shoot, what, what is it called? I'll have to grab a link to it 'cause I I've got a couple on there about. Epic epic dot. Dev. It's epic react dot dev. Epic React. Yeah, and there are two, two blog posts and you said I could put them just right here and people will see them maybe or actually I'll put them in the in the Twitch chat every day. Perfect.
That's where we want to be. So the first one is how reactive disclosures to avoid bugs. And by using use event, you are switching from the new default to the old default and and this blog post will demonstrate what the old default was and and how it caused bugs. And then the second blog post I shared is the latest ref pattern, which is basically the use event hook. And so yeah, you can actually implement the use event hook yourself today, but I just think it's so important to understand how React uses closures to avoid bugs before you start using it. And so I'm a little concerned that people are going to start over using that use event hook, but we'll see. People definitely have good reason to be frustrated by use effect.
And I've got good news for you. You basically don't need to use it very much when you're using remakes. And and when you do, it's for focus management and stuff, which is really easy. Like they're it's not complicated. So I mean relatively should never use the word easy when describing it for them, but but yes. I had one clarification throughout all that. I know it was a minute ago but I I know like Brittany had to be running node.
Is there any other back ends that remix can handle or is it all node based? Yeah, great question. So Remix, we take pride in the fact that it runs anywhere you can run JavaScript. I don't think anybody's tried it yet, but I'm pretty sure you could get it running in a service worker even. And so, yeah, we, we deploy to Cloudflare workers, we deploy to Dino, we deploy to actually Bun.
You can use Bun with Remix already. Yeah, deploy wherever JavaScript is sold, you know, like Akamai edge workers. So a lot of people say, yeah, I'd love to use Remix, but there's no way my company is ever going to let me deploy node in production. Maybe not a lot of people, but I I've heard that quite a bit.
And I think that while that is there are arguments to be had, I worked at PayPal. So like the place that made node in production at A at scale like popular. And so I'm, I'm super into that node in in production. But for those people who are like, no, we're not shipping node. You're probably using Akamai and you can, you can use remix in production with Akamai.
So, and even even in those situations, if you really just like, Nope, we're not doing any runtime of JavaScript on a server, fine. That's why Remix router is going to be a thing. So you can get most of the OR a lot of the UX and DX experience or improvements. But there, there's a point where like you cannot do better than actually running it on a server from a UX and DX perspective.
But we're going to try and make it as good as possible for people who just want to, who just want to stick files on ACDN, so. Awesome. If if that's it before the code, I'll do our little drawing. I was going to ask if that gave enough time for a special surprise. OK so we are doing a giveaway for Level up tutorials. We're an affiliate over there and we thought it would be fun to give away 5, five, I think year long memberships. Yeah, that sounds right.
So we had everybody kind of hit, hit our tweets and if you want to put your name in in the next two seconds. No, just kidding. We we have everybody. I'm going to, I'm going to spin this crazy wheel and hopefully it works correctly and I'll do five names and I'll probably do a few extra in case the five don't respond.
Man, that, that was quite the spin it. Was that was. Crazy. It's a Google color. It's a Google developer group and there. Was like a. 1000 names. It was crazy. So Matthew Wiggly. Wiggly. I don't know. Matthew Wiggly. There we go. I I read that completely different. I read it Matt the Wiggly. That's probably what it is.
OK, I think I remove and then we can do more. OK? Yep, so. Here's our second one. Yeah, I'm, I'm thinking Matthew Higley. Sorry, Matthew. If if we're wrong, yes. I'm I'm totally going to bought this one. So Clara Minova, I'm not going to attempt that one, but you've won as well. Are you are you saving me somewhere or?
Is it? Yeah, they go in our results, so. OK, not going to type anymore then. I'm see bomb C 52 looks like. Yep, I did this in an event there. Was like so many. Names you didn't even know who won. It was like such a sliver. Yeah, we're just not going to remember. I can't talk today. Remember them, Anthony?
Oh my gosh, that's tight. 10 EZ 3 cent. That is a great name. Maybe it's E cent, I don't know. OK, I I think we're good with that. We have our five winners. I'll do a couple extra in case like I don't get a response from them, but that's that's the winners for level up tutorials. I'll be reaching out via DM and via your new username. So thanks.
Thanks for signing up everybody. Thanks for watching. OK, so the goal today is that we are going to be building a fake books application written in Remix. Are we good with that? Who's excited about accounting? Dashboards are something that are important though, right? I'd be. Interested if someone did my accounting for coding cat for me.
Cool. So Brittany's going to be driving today and showing us how to code remix and I'm. Not worried at all about that. The right screen let's. See if. My guess is it's going to be a little tight because we have like a window within a window. So I'm probably going to switch this out to this mode and then often probably just take us away here and there.
So hopefully that'll work. Yeah, that sounds fine. Cool. All right. OK, yeah, if you stay on that developer blog, we can copy a little bit of that to get started. And so if you go down a little further, there's a snippet of code. You went too far. It's NPX create remix template. Oh, we're gonna do a template, OK. Yeah, so I'm gonna.
Make this bigger for now. Yeah. So NPX is temporarily installing create Remix into your onto your machine and then it will execute it. And when that happens, it will ask you a couple of questions and I will tell you the answers to provide for what we're doing. OK. OK. Where would you? Like to create it.
Go ahead and select Indie. I'll I can talk about it and let's stick with TypeScript because I can't even imagine. And then yes, let's install. OK. OK, so the the music sub genres, originally we were making these stacks and we would call them after where we were deploying them to, but then realized that didn't make any sense because you could use. We actually had two that were both deploying to fly and what became the indie stack and the Bluestack. And so we're like, well, so this is the one that uses sequel Lite and this is the one that uses Postgres. And it also is like deployed in multiple regions. So it's like cluster.
And so like, what are we gonna call this? It would just be like a ridiculously long name that had all the the features that it implements. And so we decided to go with something that does not describe what it is to force people to go to remix dot run slash stacks to learn about them because there's, you know, there's a lot that goes into the decision. The other cool thing about this is that you can actually use that template flag and point to any repo on GitHub or any just like a tar ball on your internal network or whatever, even at like a local directory, and it will generate the project for you as well.
So yeah. I think the templates team at Netlifi created the K pop stack. Yeah, that's right. I love the K pop stack. Well, that's awesome. Yeah. So this one deploys to fly or it's, it's configured to deploy to fly. You could deploy it somewhere else if you wanted. And it uses Sequel Lite and Prisma and yeah, we're ready to rock'n'roll. So if you run NPM run dev or or CD into the. Yeah, I'll have to go in and I'm going to go ahead and open up a new Windows.
So if you go with just the basics, then it will ask you or it'll present a couple of deployment targets and generate a project for you like that. So yeah, like if you were planning on deploying to Netlify for example, then I I would probably just use the K pop stack, even though we do have a basic template the like. Unless you're not planning on having a database, which I suppose not every everybody cares about having a database, but the K pop stack is is preconfigured for I I believe planetscale or something.
I think it superbase. And. K pop remix stack, let's see if I can get. It up Yeah K Pop Remix is not going to get you what you are looking for. So yeah, it uses Superbase, Tailwind, Cypress, Prettier, ES Lint, TypeScript and deployed to Netlify on Edge by default. Yeah, Yep. So a lot of the same things that we're we've got in in the Indy stack, except the Indy stack deploys to fly and uses Sequel Lite. OK, Fly and Sequel Lite.
And does it use Cypress for end to end testing too? Yep. Interesting. So we're going to do a lot of the same stuff today. OK, Yeah. So and then yeah, if you do want to change your deployment target later, then you have two options. You can either just look up the configuration files and stuff that you need to to deploy to your new deployment target, or you can spin up a new app and then just copy the app directory over and then make maybe a couple changes. But one of the cool things about Remix is that it normalizes platforms for you.
And so most of your app code will be the same. The the main differences will be how you're accessing data and stuff. Because yeah, in a serverless environment is, is quite different from a long running server environment. And so sometimes like you're making a, a database connection for a long time versus just like temporarily during the life of the serverless function.
So. So they use that as like adapters, right? Yeah, yeah, I, I think, yeah, each, each one will have different adapter like so we've got a Remix run Netlify adapter, for example. So cool, let's go ahead and and just run what we have. So if you go NPM run dev. It already installed everything for us during the setup, right? Yep, and so now you can go to localhost 3000. Where did my browser go?
The safest apps. Yeah, but we can always. We'll, we'll keep the the auth around, but we, you could always add that later to your app late so. OK, see what was in the file, file and folder structure here to kind of see what's going on. So we've got the app file and routes. I'm assuming is where all of our routes are living. Yeah, the app directory is where most of your code will will be written.
There's also the Prisma file that has, you know, database related stuff. And I will, since we're not learning about Prisma today, I'll give you something to copy into that for our data models and stuff here a bit. So actually why don't we do that right now? It is the best way to to send you these code snippets through the the chat in stream yard. I didn't think about that.
You also I need the the four digit number at the. End mine's 1988 hey, which is not the year I was born. Year I was born. That's the year you were. Born people. Think it's the year I was born but it's not. I was born in 82. Huh. Well, that's fun. OK, so I guess I need to have the correct capitalization.
So is it capital B and it looks. Like capital B and there's a space and capital P for the in the username, which is. There we go, I sent you a friend request so we can be friends. Yay. Remember when it used to be Facebook official? Yeah, we're Facebook. Friends and now on discord like no one does that and I think I had to switch it because I was getting a lot of random messages. Yeah, yeah.
I I do not allow people to unmute for as friends unless we're in the same server and then I I don't accept invitations unless I know them. Yes, exactly. So where is this going to go into the? Prisma it's schema dot prisma schema. OK oh, is this already in here or is this? Yeah, yeah. We've, we've got stuff for that was bootstrapped for you. But yeah, if you just copy paste over that, then it's going to add deposits, line items, customers, invoice. Like I don't have an extension that is showing the intellisense.
And just. Say yes, yeah. And then the name, you can call it fake books or whatever, it doesn't really matter. And now it has updated actually, yeah, your database is now In Sync with your schema. I yeah, the client was generated perfect. So now if you try to run NPM run dev, it's not going to work because we dropped the the notes database.
So it might open up. But if you were to like log in and try to use the notes part of the app then which was like generated for you, that wouldn't work. So let's go ahead. And if you go to the app directory now, go ahead and delete the notes directory inside of routes 'cause we're we're not gonna have that anymore. And the notes dot TSX file, that's the parent route for that section of the app.
It's in the routes directory. Notes. There it is. So we'll delete that and then the models directory has a note dot server where we'll delete that. What was generated for you was a notes app. So we're just getting rid of this stuff that we don't need anymore. OK, cool. So now we're gonna do one other thing that that you don't need just so we can speed up to the the remix piece of this. And that is, I'm gonna give you all of the Prisma stuff for the app that we're going to build.
So let me see if I can just move or drag and drop these files. All of these files. I'm not sure whether the user file was changed from the original, so I'm just giving you all of them and just copy paste all of those over to the models directory. I feel like I should play music during this. We can make music during this do. You and I'm sorry, which directory did you say to put them in?
The models directory, so these are files that are responsible for managing the communication between your app and Prisma. Do I do have night driving loaded? Let's see. Yeah, I was actually going to start singing Christmas songs. So Jingle Bells would be right. My son has been listening to Christmas music like for the last two weeks. I had a guy I used to work with to cheer him up. He would listen to Christmas music. Any, any month it does cheer you up, right? Like, I mean, I, I can't blame him, but there's a reason I made a, a separate Spotify account for my children. So.
That's a great idea. That is a great idea. Cool. OK, so they. Have kidz bop on mine. Nice, cool. OK, so now we've got a data model. We have ways for accessing the data. Now the last thing that we need for the data piece of this and yeah, there I I'm glad that we didn't actually just like have you clone something directly so you can see these are the things, you know, concerns that are common for building an app.
This should be the last giant piece of code that you're gonna. Copy and where does that one go to? That will go in the Prisma directory. And the Prisma. So right there, right? Just at the group. Yep, and it and then you can delete the seed dot JS file 'cause we're not using JS. And actually there is one other thing you're gonna need to do.
I forgot about that. In the package Jason, there is a Prisma property at the very bottom and it is referencing the JS file. I totally forgot we changed that. We need it to reference the TS file. So we're gonna use TS node for that. And the other thing is we, we'll probably, Oh no, we've got TS node installed already, so we're good there. So this is the right command.
I I just sent you Oh. You sent me a new one? Yeah. Oh, OK. I see. It's basically the same thing, but it just allows us to to run. It has TS node instead. Yep. There we go. Cool. Yeah, I guess that was the only thing. Just add ATS dash. So cool. Great. So now you can open up your terminal and run NPX Prisma DB seed. All of those have spaces between them and that will get some seeded data into your database.
OK, the seed command has been executed. Booyah, so fun fact, it has that little emoji with the plant growing. So they did not used to do that. And so that's why I added database has been seeded that that log was for me with the emoji. And I think I don't know any whether this is true, but I think that they saw that I did that and they're like, oh, what a good idea. And they stole my idea.
So now you have two of those, but like I said, I don't know for sure. Anyway, now we've got data in the database, we've got a way to access it. Let's finally get to the remix piece of this and make a route that just displays our our customers. So if you go to let me just think of the way that I want to structure this. Yeah.
So let's do yeah, let's see, see, I don't wanna like give you too much 'cause we do wanna create some of this stuff, but let's just make it a go to your index dot TSX route there. Actually, you know what? Let's let's make a brand new route. We, I was gonna modify this one, but we'll make a brand new one. Just call it customers dot TSX.
We'll probably delete this later, but I want to just demonstrate a couple of things here. So now we are going to create what is called a loader. So you're going to export a function called loader. Is it construction loader? Yeah, you we actually I used to do construction loader, but now we we changed the way our our typings work and it works a lot. I I just prefer function declaration. Reader and like.
Function declarations are where it's at anyway. So now consider we're going in here, we're going to grab the customers, the list of customers. So hold on a second, where did my? So we're going to get a, use a function in our customer server file called get customer list items. And we've got a special way to import those things that's built into Remix, and that is to use this little tilde.
No, OK, it's not in. Not customizable. This is something that I do with felt kit is the alias with the vconfig is we can do. It comes with a dollar sign and I don't like the dollar sign so I use an AT symbol but. OK. Yeah, we do at slash for everything. Yeah. So there's something to be said for customizability.
There's also something to be said for copy ability. And so making it so that it's the same for everybody just makes it easier. Convention over configuration, right? So, yeah, get customer list items. So this is for listing our customers out. So if you go to line four and have a customer's variable that's assigned to get customer list items, yeah, just like what Copilot is saying.
Yes, I love copilot. So instead of just returning customers, though, we're going to return a response and we have a helper to create a response. But you could literally just do return new response and then Jason stringify and all of that, that stuff if you wanted to. But we're going to use the helper. It's called Jason and it comes from Remix run Node. OK, So what?
If you type out Jason, it should actually auto complete. No, all lower case. It's a function and you're gonna go, Nope, not that one. Yeah, there's other. There's Jason. Things it did import something from stream consumers. Yeah, that's not us. That's not right. Yeah, I think that's a control C thing. Maybe Intellisense?
Yeah, it's sort of that one. So you can you can tab that one and then change change server runtime to node. To node runtime or just node? Node. Whoops. Not that node. There we go. OK, so now you're going to call Jason and just pass it the customers? OK. And then you'll want to return that. OK, OK, sweet.
And what you've made is a resource route. So since we don't have any UI that's exported from this route, remixes saying oh you just want this to be like an API? It's an API endpoint, yeah. Yeah, so no API directory or whatever you'd put these wherever you like on on my site you I have the ability for users to download their data and so I just made a resource route at me slash download dot Jason and.
So then on line 10, just above that line, we we need to get the customers from somewhere. You're gonna say constant customers equals use loader data. Constant customers, not that use loader data, yeah. And that's coming from Remix. Run React. There we go. That one worked. That one did work. OK, so TypeScript is going to complain. Let's just stick with this for right now and I'll show you how to make TypeScript happy.
So save that and then go over to your browser and refresh. We can't do automatic refresh on a resource route, but yeah, so there you go. There your. Customer. So just in the same file you have your loader Nice. It's it's very similar to Next JS where you use like get static props or get server side props and just return it in. But it's not coming in as props, you're just using the loader data hook.
Yeah. And then on top of this, we I'm guessing we're not going to have time for this date, but maybe if we add a mutation and we added a customer to that list, then Remix would automatically update our data for us. So yeah, people, people always say, oh, loaders just get static props. No, no, no, it's nothing like that. It or, or get server side props.
This is so bad. So you're gonna update your used loader data to use a generic that looks like what I just sent you. So, so we may get here, but I, I think the thing that Brittany and I were talking about before this is trying to understand and, and you answered a lot of these questions before it came for me.
But how this will end up being faster than a statically so get static props in next JS like and I know we're like apples and oranges type of scenario here but do we want to talk about that now or should we just get through? This we can talk about this. So if you did this statically, then your list of customer oh, and by the way, Brittany, you just did it type uploader. Boom, now everything is typed across. The wire, everything just works.
That is it's magic. It's amazing. I love it. Yeah. So like, it's it's nuts. It's so cool. So, yeah, if you were to do this statically, then that list of customers would be and would forever be what they were at the time you built your site, right. And so that's probably not going to work when you start thinking about, oh, I just added a new customer. Do I need to rebuild my whole site again? No, I don't want to do that.
I'm reinventing what the platform does. So like I, I could go on on a big thing about ISR and how it's just like trying to reinvent what the platform already does. But so, so then you're loading in the client. And so that, what that means is that the browser has to go to the CDN to go get your JavaScript and, and all that, you know, HTML, whatever. And then it has to make a request to go get the data. And your data, it's gonna request is gonna hit some endpoint that is indirect, some indirection there. Like what I've got to find what the URL is. I've got to make an API route and all of this. And now, so like the developer experience is worse, it's not in the same file there.
And so when that response comes back, now we have all of our customers. So this is going to be faster. And in our, our demos and, and comparisons, we found that even the initial page load of like time to 1st bite, of course it's going to be faster on ACDN, but it actually is not even that much faster. Especially if, if this matters so much to you, then you'll probably want to deploy to the edge and you're looking at like 100 milliseconds, maybe 200 milliseconds. That's fast enough.
And, and no loading spinners or anything like isn't, isn't it neat how we've just written all of this stuff and we haven't talked about a pending UI at all? Like it's, it's literally just like I've got my customers on the page. There's no need for a pending UII think that's pretty cool. Now of course, I think the.
Biggest thing is it's been like that time to 1st bite and lighthouse scores and like how how that starts to look. I guess is is always my biggest question because for all of our stuff, like when we're updating blog posts and releasing like yours just came up. So like you were on our schedule, our schedule needs to update 'cause you'll fall off of it when we pull you off. We actually have to have a web hook triggered to do the rebuild, not rebuild.
But what's the word revalidate on on Versal and have that come up. So to me, like I love the idea of not having to do all of that but still get speed out of it. So if that's kind of the win here, like me conceptually, like at the very high level of this, I'm all in. Like that's great. Yes, that is what it is.
Go in here and it is phenomenal this is when I rewrote my site in remix I didn't totally get that that aspect of it before I started and after I was done I was like oh shoot like all I want to do is talk about remix now and so that's what I do so cool cool OK so yeah I don't want to gloss over the the typing awesomeness here like this is phenomenal getting like with just that little bit you get type safety over the.
Wire a really great developer experience. Honestly. And there's no fancy. Like and this is parsable too, which is one of my big gripes about TypeScript is that it makes the code just completely unreadable. Yes, absolutely. There's one thing of TypeScript in here and that is the type of loader data. And I think just about anybody can, you know, even if you don't understand what it's doing, like you can gloss over that like just like, well, I do this and now the TypeScript red squigglies go away and I got autocomplete so. That type of loader that is coming from remix, not prismic, correct?
Yes, yeah. So that use loader data hook is a generic and that's coming from Remix and the generic has been codified to be able to to deal with the loader function like that. Is this what it is coming out as? What's popping up here? Yeah, yeah. So actually if you hover over the customers then you'll get a better view of what that is.
Yeah, there we go. Yeah, cool. OK, so let's let's make this look a little bit nicer. I'm going to grab. Let me see, just make sure. Yeah, see, my finished version has a bunch of nice fancy things that I probably should have spent a little time getting rid of for our our stuff today. So let me get rid of this here really quick. Choosing tailwind, right?
So we've got some tailwind styles in there, I'm assuming? Yeah, Yep. So let me grab all of this. I think I'm just deleting stuff to so that you don't have to. Like this is stuff that you'd want to have later when when we're done, but I don't want to add it right from the get go because I think that would confuse people.
So here we go. Thanks. So that hopefully that all works. OK. And where does that does that go? Right under? Here, just take it in in place of the customer component that you've got already. OK. OK, so now it's complaining. Oh, shoot, yeah. To import all. The and stuff. Dang it, components. OK, so and it's oh, complaining about the customers is. Actually a question I have.
So these are components. Where's what's the convention? Just making a components folder in App? Yeah it kind of depends. Like so you can put a a components thing in the route directory and then you can configure remix to just ignore it and not treat it like a route. So you can Co locate components if you want to. But thanks to the tilde alias thing, it's actually not too terrible to just make a components directory, especially for smaller apps.
If you've got like a big app that's got like tons of sections and routes now I would probably Co locate those things. But yeah, for something more simple, I I think I just put it all in a components directory. So let's, let's fix all these errors as we go. Line 7, you're going to want to turn that into an object. Instead of just returning to customers, you return an object that has a customer's property.
Great, awesome. And then there I think it's just the one component that's left and you can just delete that or yeah, just delete the file plus icon. No, leave everything else. We want to create the new customer eventually, but just so. Oh, you mean yeah? Delete the icon component that you don't have. I could give that to you, but I don't think we need that for. What we're doing, it's just we could throw an emoji in there or something.
OK, so since there was an application error, you're not going to get a refresh, so you'll hit reload and there you go. So now you can click on each one of those and you'll see like it says, hey, not found. This is because we don't have that route yet and we'll create that here in a second. But yeah, each one of these is coming from your Prisma database.
If you go create new customer, that route will go to customer slash new. And let's go ahead and I I think we should create that that route so we can see this nested routing magic. So let's make under the routes directory, you're gonna make a new directory with the same name as the the parent directory. So it's customers is the the route, the parent route for the routes we want.
So customers is gonna be the name of the directory and then just. Get thrown into. There no, it will stay where it's at because it's the parent layout route and then in the customers directory we're going to make an index dot TSX and then here you're going to make Oh yeah ignore that for now here you're going to make a component so you'll export default function customers index if you want to call it that actually, you know what maybe I should just give this to you so we're not wasting our time there's not much to this one Oh yeah here, yeah we'll we'll I'll just give all this to you and then we can talk about it 'cause it's kind of cool so copy paste this into your the.
OK, so you want the one that has you don't have any customers with a thawing emoji. There we go. All right, sweet. Save that and then go ahead and reload again the error. Oh, right. So go to flash customers. Oh yes, well, I'll explain why this is happening here in just a second. Let me give you one other thing. And I'm trying to just make sure I'm not giving you more stuff than we've talked about already.
So we're. Going are we confusing the router because we have a route of customers and an index route of customers? No, no. I'll explain it here in just a second. OK, so this should work. I'm gotta like remove all of the features that we haven't talked about yet. OK, I think we'll get rid of that also.
OK, cool. So I'll copy that and give this to you. OK so copy this into a new file under customers called dollar sign customer ID camel case dot TSX. Customer ID like that PSX. Yep. OK. And then paste that in there. What the devil? Why is it complaining? Oh, it just it just needed a second to it's complaining about this though.
Oh. Currency formatter. Good grief. What is that used for? Yeah, OK, go down to line or to where that's being used. We're going to just delete it. We don't need the currency formatted. Oh, OK. Or you know what, may as well may as well let's I'll just give you the currency formatter because you've got the utils file already. So here is the currency formatter and that you just put in the utils dot TS file.
Just stick it at the bottom. OK, well, and these are just. Not being used? Yep. So save that and then refresh and we should see. Now see something? No. What the devil? Oh, it's. I see like it's doing something here with the route. I'll I'll explain what's happening then we can debug it together. So if you go to the index TSX file in the customers, you'll see the loader there.
It's the first thing it does is it does get first customer. If there's not a first customer, then we'll just return Jason empty and then you'll render you don't have any customers Sabi face. But if there is the first customer like I, I'm guessing you're probably going to want to select a customer. You don't need to see like a message that says select your customer.
Actually, I think I might know what's going on. So if there is a first customer, then we're going to redirect to that first customer. So that's why you can't get to slash customers. It's because we're just gonna like, we're gonna assume you're gonna wanna select a customer. So we may as well just like the first one for you.
And this this will make more sense when it actually starts working too. OK. So if. I see what's causing the redirect though. Is this line here? Yeah. OK, and that that again is just a a helper function from remix that creates a new response. So you could literally just say return new response null and then give the header's location and it is whatever that is.
So there's not like a bunch of magic weirdness going on here. This is all just platform stuff, which is some helper APIs. OK, so the I I'm a little baffled by why we're getting a 404 not found if you go to customer ID that route. Oh, shoot, yeah. And I forgot to. You can Dang it. Yeah, See my my code is a little older and it still has like older TypeScript stuff that we used to have to do. And now you don't have to do that anymore. So stuff on line seven through 10, you can just delete all of that.
This. Whole thing, yeah, just that whole block. And then you'll go to line 16 and delete that loader data thing, everything between carrots inclusive. And then on line 24, you can add the type of loader data or type of loader that we had before and then delete the add loader data. This is way better than it used to be. OK, so my guess is, so we are getting, if you save this here, you know what, it's very possible that this 404 is coming from our loader.
And So what we're gonna do is I'm gonna teach you a new thing for error handling so we get more useful error. So this is called a catch boundary. And you'll stick this at the bottom of that customer ID route. And it's just a function that you export called catch boundary. And if you save that and then go and refresh, let's see what happens. Yeah, it's still.
It's what that is saying is that there's no. Mentioning an outlet. Yeah, we are missing an outlet, but that still shouldn't. But maybe it is. Go to, go to the customers file and we'll just add that really quick. OK, the customers dot TSX. And then Scroll down to where we have the dot to do with a component called outlet that comes from Remix run React.
Is it self closing? That's the one. Yep, and save that. It's not importing it. It's coming from Remix. Run React, you said. Just add it to the import online too, OK? Yeah, so it's still not. That is so weird. I don't maybe restart the server that that would be very unusual. You should not have to restart the server for this.
So I want to call out a couple of things here. First, I want to I want to talk about that catch boundary that we added because we added it, I want to get it out of the way. So if you update the URL in just in the URL bar, just change it to some some nonsense for the ID. Now you're going to see no customer found with the ID of whatever. So now if you go to customer ID and let's look at that catch boundary for a SEC.
So this is just saying or actually before we look at the catch boundary, go to the loader above. This is responsible for loading the data based on that customer. So you'll see on line 7 it's accepting params. This is because we are using a dynamic route param route name with the dollar sign. It's saying OK, so anything that that would be along in this segment of the URL, I'm going to call customer ID and I will pass that to your loader.
I'm talking about line 10. But yeah, so then we say, hey, get me the customer details for this customer ID on line 12. And if there are no customer details, then we are throwing a new response. So that this action of throwing a response is saying, hey, I don't want the rest of this to execute because like, it's nonsense.
We're in a, an error state. Something is not right. So we're gonna stop execution. So we're gonna throw and Remix is gonna catch that and it's gonna say, are you a response? Oh, yes, you are. So I will actually render your catch boundary instead. And so it won't even get into your default export. It will just go straight to the catch boundary where you can say, OK, So what was the thing that was thrown? What's the response?
What's that status? Oh, it's a four O 4. I know what to do with the four O 4. I'm going to say they didn't have a customer found. So you mentioned that those params are being used over here, which is why we're able to get these nested dynamic routes in the same route. Yes. So that outlet component that you added is saying hey I am a parent route, I'm a I'm a layout route and if I have any children this is where they go. OK, so that's like a slot in spell I'm trying to make my. Slot in spell or or in the it's transclusion in angular JS it's the the children prop in in React. So just just for everybody else, when they when you catch that and do a 404, that's almost like no JS having a response of status 404.
What? Happened to be very like a different. Yeah, it just breaks if you throw. Yeah. Cool. Well, so and you could handle that as well if you wanted to. So, yeah, you just have it be whatever you want. The most sensible thing is a four O 4. This will be an actual four O 4. So like a user lands on this page, they're getting a four O 4 status code. Their browser will be like, hey, this, you know, couldn't find it.
Do you want me to use a cache version or Google will do the same? And so like status codes actually matter. I, I don't know, like we kind of got into this thing where everything's a 200. It's not. So yeah, so that's what's. Going on. It's not OK yeah exactly. So yeah throwing a response, you could throw a 200 if you want to throwing basically just says I want this to go into my into my catch boundary. So that didn't work because our catch boundary is only handling 4 O fours.
If you go down to the catch boundary, we just have an F that says if it's not a four O 4 then just throw an error because I I was not programmed to handle this case. But yeah. So if if you go to a nonsensical ID now, it still works. It's the same thing, yeah, but. The browser is going to behave differently in caching and all that too. So yes.
So yeah, there you go. We got a little exploration and error handling and making sure our routes are correctly configured. So let's see yeah. The other thing is I I wish that we had more time today because it would be pretty cool to talk about like how awesome this nested routing is. Because in a, a larger application where you've got like dozens of people working on your app, you will have like the shell of the app, the header, the footer, maybe a left NAV. And you've got like big companies I've worked at. There are teams that are responsible for that entire experience, like the, the header, footer and left NAV or a team responsible for the header, A-Team for the footer and a team for the left net.
Like just really big, you know, many teams working on all of this. And without nested routing, that's a really difficult thing to coordinate. And now you're starting to talk about micro front ends. And that's what I was just going to say. So with Remix, if you actually if you want to share the screen again, we'll go to the customers dot TSX.
And I will, I will say we have, I mean, if you want to go for another hour, it's up to you. Yeah. Yeah. Time, but I want to spend time in in mutations. So this is this will account for purposes, I think well, the customers here, this is responsible for everything you see on the left of the screen, create new customer, the list of customers, all of that.
And there's nothing in here that cares anything about the children other than where they go, which I think is is sufficient level of power for this parent, right? Says if I have children, this is where they're going to go. And then the customer ID, if you go to the customer ID route and the in this component, there is nothing in here that says anything about its parent. It doesn't know anything about the parent. It doesn't care about the parent. It's not passing prompts, it's not loading data, it's not doing any of that stuff for the parent. This is really.
Yeah, it's just. It's just because the folder structure is called customers. So that the association is created because of that. So like Remix, the remix convention creates the routes based on that folder structure, but but the key here and, and so this would apply the same with with Remix router without like Remix server and, and this folder convention, the the fact the the key is that it's nested routing. And so what's really great about this is the customer ID route doesn't know anything about its parent and the parent doesn't know anything about the child.
We. Don't care. Now, yeah, so and the parent doesn't care about the child either. They they're negligent. But this, this, this makes like this is significant because. It really. Is that's you don't need coordination. So who needs a micro front end? The the only reason left to do a microfront end when you're using Remix is if you want to have independent deployability, you want to deploy separately from each other.
OK, I still don't quite understand why, but if that's what you want, then yeah, still. Microfront really see the value in this because you're like you said, you're not passing data from the parent to the child the child isn't giving. I mean it is giving data to the parent but it the parent doesn't know about it. Yeah, like.
It all lives in this other file. Yeah. Are you are you passing way less props like for all of this? Like you don't. Have to do props. Yeah, it's, it's kind of crazy. So you don't need provider, you don't need like I'm trying to rehash all that. Yeah, I. Think you're basically. Don't use context except for like if you have a component library that's like a a menu thing, you're probably going to have context for those compound components and stuff.
But that like that's easy. Like, yeah, yeah, simple stuff. Or we're talking about application state management, There's there's nothing we haven't used use state yet. I know I I'm like blown away so far. Yeah. And we haven't even gotten into the really cool part, which is mutations, which I think we'll get into next. So if you go to create new customer, click on that, I think we'll actually get our catch boundary because we don't have our new TSX.
Yet I'm sorry, create new. Customer in in the app, if you click on create new customer at. The top Oh, I gotcha, OK. So no customer at the idea of new, there is never going to be a customer with the idea of new. We want customer slash new to show us a customer form. So let me again go through this and delete stuff that we are not going to be using for what we're doing here actually and I won't give you the action yet either.
So let me just whoops that. I actually really like how Kent's like, piece mealing this, like we don't get lost in all of it. Yeah, I I'm hoping that this is this is helpful. I think this is great. I think this is really breaking it down actually, without having to code all of this. And it looks nice because you've got the Tailwind stuff in there. I I.
Have to be like fully honest with you can't like I've I've gone through all the remix and like checked it out. I'm like why is this any better than next? But now things are starting to finally. Like you've got to use it. I'm like, oh, I see. Oh, I see. Yeah. So this. File. I shouldn't say better or worse. This just this file that I I sent you put it in just in the the app directory just like next to DB dot server. OK, Yeah, sweet.
So in the customers directory a new file and you said. Customers. New dot TSX Yep, get mad at me. OK, now we have the form. Sweet. And it looks nice. Thanks, Tailwind. Yes. Tailwind. Love it. OK, so now if you were to to fill this out and everything hit create customer, it's going to make a a fetch request and it's yeah, it's going to say four or five. I'm not allowed because we're not actually handling the any POST requests to this particular URL. So, so if you go to look at the code here, we'll look at that form.
OK, so we're going to make a action function. So you'll notice on the form there's that prompt called or there is a prop you can provide to a form called action. That action prop specifies where you want the POST request to go. So you want it to go to the root direct route right now, or you want it to go to slash, API slash, whatever.
For us, we want it to go to the current URL, right? And that's the default. So when you make a form and you don't provide an action, then it's going to make a request to the current route. If you don't provide a method, that request will be a GET and it will serialize the form values in the URL. Here we're saying we want this to be serialized in the POST body.
So let's do method POST. With a regular form, you only have two options. It's either GET or POST. You can't do DELETE, you can't do PUT, You can't do any of that with a regular form. With the uppercase form, you can, but I recommend just do just do the regular post because that is progressive enhancement magic, which is is nice.
So it'll work whether or not JavaScript is on the page. So and we can demonstrate that later. So if you go into line three, we're going to add a function to this and it is called action and it's very similar to a loader. So you have to export. It. Yep, export async function action and then this one we actually need to get something. Yeah, No thanks.
Not that. We want to get a something from the request right 'cause now the request has our form stuff. In fact here. Comment that out for now or or don't save the file. Go back to the browser and open the dev tools Yeah on new Yep, there we go and then if you type in fill in or or go to the network tab start, we want to record what's going on in here. Don't in Firefox you gotta.
How do you do? OK, you can open up up in Chrome. I don't know how to use Firefox. I don't. I like the same as tools. No I'm not. There are lots of people that use Firefox. Thank you very much. What were we at Slash? Customers slash new. New. Oh wow, what did I do? I'm zoomed in. OK, so now if we go here, this can be bumped down to the bottom and network and record.
Yeah, that is much. Oh, you just turned it off. Yeah, you don't. Yeah, Chrome is recording always. I don't know why Firefox isn't just always recording. Yeah, OK, great. So now let's look at the request that was made and you'll look at the the payload. So this is what was in the request and the the browser actually knows how to take what you have input and stick it in the payload.
This happens automatically whether or and and what Remix is doing. Since you're using the uppercase form and we've got JavaScript going, Remix just does the same thing the browser does. So if you change that to a lowercase form, you're going to see this request and it will look exactly the same, like mostly the same.
There's some implementation details here, but. But yeah, you're going to get the same experience. Yeah, you need to go back and, and you'll want to refresh or. Yeah, actually I think, I think that works in any case, like the the point is that the browser knows what to do about requests like this. It'll say, oh, you're submitting a form. Let me take all of the inputs of that form, one of which was actually a hidden input, by the way. That's where that intent create came from. And yeah, if you look, if you go up to the top, you'll have or maybe it's at the Oh no, no, no, it's the button that you clicked.
So the submit button has a name intent and a value create. So because that's a button or submitted, then that's the one that that's the value. So yeah, so the browser is going to take that, put it in the request and send that to the server. And so our action is going to take that request and get the form data out of that.
OK, That's what we're that's what the last five minutes was. That's what we're going to do. So your action function is going to accept an argument, and that argument is going to be an object that has a request property on it, and to make so it's a full full request. You have to. Yeah. And then that the type for that request is gonna be action ARC. So here I'll just give you that whole line so we don't have to worry about talking past each other or anything. Oh yeah.
Over node. OK, OK, I'll change this back to form before I forget to do that. It'll work either way. That's, but let's leave it with the lowercase form for now. OK, cool. So now to get the request that here's the cool thing. If you look at the type definitions for that request object, so hover over request, you'll see it's a request. If you click into it and then click on the, click into request the uppercase request there.
That takes you right into the the TypeScript definitions for fetch. So this is not a fancy Remix thing. This is just a regular request object that Remix is giving to you. Whether you're running on Netlify or Versal or Express or whatever else. It always normalizes all of these requests and response objects to fetch API the.
Regular fetch API that is awesome. Yes, it is because as as you get better at using Remix, you're just getting better at the web platform, which I think is is pretty rad. That is. So. The more we can standardize to the web platform standards is better. There's just there's so many different ways to do things and standards. Yes.
So Speaking of standards, there is a standard way to get things out of a request. People probably familiar with request dot Jason, but there's well or response dot JSON, but we also have a request dot form data. And so if you say request dot form data, and that's a function that you're going to call, it's an async function and that's going to give you a form data object.
So assign that and it's a promise. So you'll want to. OK, so. I just call it form data or you could call form. And assign it and it's async. So you all wait. Oh wait. Oh my gosh. Yeah. So it's. Friday. Yeah, so the form data object, that also is just web platform stuff because again, this is all just like the built in objects. So form data.
You can go to MDN to learn about how the form data API works. But yeah, it's, it's an iterable. So you could iterate over all of the entries. You can say dot entries to get everything and turn it into an object, object from entries. But we're not going to do any of that. You'll we're going to say form data dot get and we're going to get the pieces of data that we want. So one piece of data.
Yep. So you're going to say GET and then we want to get the name and the e-mail. You could also get the intent to make sure that the request is being made properly. But no, this isn't how the API works actually. So you when you call GET, you pass it a string of the property that you want to get the name of the property from the form data. And so for us, we're going to get the name A. String and then you said get the name. Yep.
And then that's gonna return the name. So no, no extra prams. No, no, no, sorry. Maybe it'll be easier if I do this? Name e-mail like this. I'm not looking now 'cause I'm sending it to you, yeah. Oh, OK, so OK, let me start. A code of cards. Sometimes name equal. Oh I know form data dot git and this is a new API for me, so I'm not. Yeah, Yeah.
Well, it's new for most people, like it's been so long since we used the platform. I see. Yeah, I have never used it like this. I would normally, like you said, do the response dot Jason and. Yeah, yeah. But for us, this is encoded as as URL encoded form data, which is the way that the form is going to be submitted by the browser by default.
And so you can change it to you, you can submit Jason if you wanted to. Like if you're want to communicate straight from the client to some third party endpoint that only takes Jason, then yeah, you totally can do that with Remix. But the default for Remix is a focus on progressive enhancement and the platform.
And this is the way the platform does it. Now, if you don't like this form data dot get and that's like, oh man, what if we've got like 300 things? I don't want to have 300 lines. Then yeah, you can totally use form data dot entries. Use object dot from entries and boom, you've got an object. But most of the time, especially for smaller forms like this, I'll just do form data dot get for everything. OK, so now if you want a console log name and e-mail or just trust me it it works we can move on to actually creating the customer.
You, you can go ahead and talk. Yeah, we'll just see what it. And then the name and e-mail or those logs are going to show up on the server because again, this code runs on the server. Yeah, it it's warning because we're not returning anything we're we're supposed to. But if you look at the terminal that's running your server. Oh, OK.
Then you'll see that scroll up and boom, there it is. Yes, there we go. Oh. It's running on the server side. That makes sense. That's why it didn't come through on the client. Yeah, and this is great because let's say you're integrating with a third party CMS or something and you've got private keys. You don't need to make some sort of special API endpoint for hiding your private key.
You're just like literally in the same file where the form is, and now you're writing server code. And so you can use that private key and not worry about leaking it out. Or in our case, we're going to talk to the database. So we've got a function called create customer that you can use that is from the customer dot server in our models directory and.
And this is an async function. It's the TypeScript is complaining here. I can TypeScript is stupid something well, it's not too good. TypeScript is totally right. So The thing is that as far as as reality is concerned, that name and e-mail can be one of a couple of things. It can be null, like the form wasn't submitted with that information.
It could or it could be a form data entry value, which is either a file or a string. Cause like the user could be uploading a file, right? So TypeScript is just saying, hey, create customer expects a string, but you're sending it null or a file or a string. So what is it? And so here's what we're going to do to fix that.
You're going to import a package called tiny Invariant, and then you're going to use this invariant stuff right before you call create customer I. Have not heard of this. That invariant is actually. I don't know whether it was created by. It was at least made popular by the React team. And then somebody made a like a tiny invariant. So it's It's small with regard to bundle size, but what? That line 'cause you had it set to a variable, so I. Yeah, yeah.
So that that's working now. So what what we're doing is we're saying, hey, if the type of name is a string, then everything's good. But if it's not, then we're gonna say, you know, throw an error. Now we we could do better error handling here and send a a response to the user and say, hey, this is messed up.
But we are limited on our time, so we're just making TypeScript happy for now. OK. So sweet. Now we've created a customer. We've got that customer. Let's redirect to that customer's page. We just created them, so they should have a page now. And so to save a little bit of time, here's the oh, just kidding, it's not slash sales.
We made that mistake. Before help fix it. There we go. OK. And we just want to return redirect and we're redirecting. Where's redirecting coming from that? Should come from Remix run node so that yeah, and you can delete the type on on line four. Yeah, that should work. So save that and then come over. It's it's complaining because action arcs is only a type thing.
It, it doesn't matter, it's fine. So if you come back to the browser and submit the form, I want us to watch closely what happens so. It worked. There was nothing in our code to say when there's a mutation, let's go and update that list of customers because it's wrong now. So let's set state and here's my new customers and all.
If you go to the new dot TSX file in the new customer and you'll see the form on line 22, that is a lower case form. Yeah, so we. Were not using JavaScript to submit that form data. And there's no action posted here either, so it's it just knows to use this action. Function yeah, Remix is handling that request and says, oh, here's the the route that you're posting to.
I know which action to post to. So what's happening here is I just showed you progressive enhancement and that you don't need state management with Remix, No state management. The thing works without JavaScript. So it, it must be able to work without state management and it does and it's amazing. But we do want to have JavaScript. We don't want to do a just a regular form because that's going to do a full page refresh and that's stupid. Who wants that?
That's gonna good thing is not sending emails 'cause that might be someone's actual. For Alex. So there you go. No, no innocent, no like weird API routes, no indirection, no use effect. All just like regular web APIs and this. Kind of makes me like React. I know that's the. Like I. It like it gets rid of all of the things. You I don't have to use the use state hooks. I don't have to use use effect.
I haven't used anything that I'm like, oh, I don't like this. Yeah, Yep. So that that's, that's remix for you. It's pretty pretty rad. I forgot we weren't on the screen. I was like looking at you all. We're all like happy. This is pretty cool. Yeah, I mean, we, we could get into stuff like pending UI and optimistic UI.
Things aren't always fast, but that's like these are the the main things that make Remix so special. Like we everything we've done so far doesn't even need JavaScript in the browser, it's when when we. So if you were shipping just this and you were happy with this experience, then I would say just delete the the if you go actually into the root dot TSX file.
So it it renders out all the script tags for all the modules and everything that we're loading. You could comment that out and the entire app experience will still work You go refresh the browser, you click between those links and you go create a new customer. Everything still works. And so if you were happy with this experience, like one nice thing is that this the browser will show a pending UI, the favicon will spin the, you know, like mobile browsers will have the little, you know, status thing that goes across whatever. So like you, this is actually a better experience than having the scripts because we haven't actually thought about pending UI yet, right?
OK, so the way that it works, the way that what's happening is you submit the form that goes to the back end remixes like, oh, here's the route. You're making a post, let me find the action, let me run the action with the request and all that. You update the database and then you send a redirect response. That redirect response goes back to the browser. The browser's like, oh, you want me to go somewhere else? Let me go to where that location header says. So now it's making another request to your server to get that new location.
Your server's like, oh sweet, I know that. Let me go look up that customer in the database that I just barely created. We generate some HTML and send that back to the browser. So that's how it works. It's like old PHP. Yeah, that's exactly what PHP used to do. Now what's cool though is that this is way better than PHP because we can uncomment that scripts tag and now we can start adding stuff like pending UI and spinners and optimistic UI like adding a new customer before they're actually created in the database.
All of a sudden you've got all of the power of React and it's all the exact same code that's running on the server and the client. And so you can say, oh, if the user just submitted a form, let me add this new customer to this list just optimistically 'cause we're going to assume it's going to work. And then when it's done, Remix will automatically go and update the data and that new customer will be in the the new data that you just got.
So the optimistic stuff naturally goes away. New customer is there it just yeah, the you. What's cool about Remix is that it gives you the mental model of the late 90s, early 2000s, but the the power of 2022. I kind of, I kind of thought all along like that, that's what the static piece was giving me and then the like rehydration and client side. But like this is even closer to that web standard. I guess that's.
Interesting. Yeah. Well, and on top of that, I. Just I want to make sure we don't miss this and we just covered that, but I wanna make sure I'm not reading it incorrectly. Yeah. OK. So when doing a progressive enhancement, say I want client transitions, but it required the response before it can animate.
Yeah. OK. So like let's say that I think I might be misunderstanding that question. Actually, I might too. So let's say we're creating a new customer and we're gonna redirect them over to the customer's page, right? Or something. Actually, can I share my screen? I think we, we can skip ahead to to the end here and I can show you what, what the end state is of what you can do with Remix.
So this is a, a different app that you can actually use. It does actually work. You can create an account and everything, but it's the good old to do NBC if you remember that. So I can make a new to do and this is great and I have it coded where if you include the word error in your to do, then that will throw an error and say to do's cannot include the word error.
So maybe you cannot use this for your own To Do List because you'll never be able to use the word error. But here's the cool thing, and I think this touches on what the question is. How do you do pending UI when like there's an element of web application development that you do not control and that is the user's speed of their browser, right, or, or speed of their network, right?
Even the user doesn't always control that. And so you do have to think about pending UI. So if I slow this down, and I say here, let me actually we're not gonna slow down. I don't wanna spoil this. So we're gonna here we'll toggle them all, we'll clear them all and here we'll just do a full refresh.
OK, so now if I slow this down, watch this, I'm on a slow 3G network. If I do that to like to Twitter slow 3G and I'm here waiting for spinners and and all of this stuff too. I'm gonna leave Twitter up though, because it it's I wanna use it for something else. So I'm gonna slow 3G network. This means that network requests are gonna take at least 2 seconds.
Is what the browser will do. Why then is this so fast? And check check check, it's all super fast. What? Why is it so freaking fast and. There's some errors in there too. Yeah, we've, we have some errors here. I can delete this, I can clear the completed, I can do all of these things and the whole experience is feels like I'm on a really fast network. So what's what we're doing is optimistic UI. This is Twitter does the same thing. So if I, you know, let's not make it slow. No thanks.
I don't need notifications. From Twitter More notifications. OK, so this is a test. I open that up and I say I favorite that and then here actually, and let's slow this down. If I unfavored it on a slow 3G network, that's going to take at least 2 seconds, right? But it instantly is gone, right? It's instantly unfavorited.
This is optimistic UI. It's a really common practice for the web. It's not as common as it should be. But the problem with optimistic UI is what if your optimism is misplaced? So I delete this tweet and then I try to unfavorite it and it instantly unfavorites. And then Twitter's like, oh, actually, sorry, that tweet was, was deleted.
You can never unfavorite it. You're you've favored that tweet forever. I see this in Twitter all the time and I thought it was like buggy. Yeah, no. So like, what do you, what do you do when you're Twitter and somebody's on a, a tweet that has already been deleted? What they are trying to do is they're trying to say, hey, let's, let's just make this seem like it's really fast because 99.9% of the time this is gonna work. And so we'll just automatically make it look like it's done. And then if it's not, we'll roll it back, you know, and say sorry, you know, give them an error message. So that's the same thing that I've implemented over here. We have optimistic UI.
So it is fast. And even though you can see in the network tab like those, those requests are taking at least 2 seconds to complete. And then for like the what makes optimistic UI really hard is fall back. So if your optimism was misplaced, the tweet was deleted or whatever, then how do you fall back to a state where the user knows that oh, like something was messed up and I've got to fix it. Or, you know, you, you bring the state back to where it was before.
And so I've implemented that here. So I can say 1 error 2-3 and then when error comes back and says hey that that's not allowed, it just pops right back in and it says hey to do cannot include the word error. So now I can fix it and it will try again. Kent What What happens if you shut off your network and just put fast in? Yeah, yeah.
If I if I'm not connected then you have to start thinking about like offline mode for your app and Remix doesn't currently do anything. I just didn't know if it would drop in and then pop. Out, yeah. So I haven't programmed anything in here for handling when a fetch fails, yeah. I deal with the Firebase all the time, that's why I was kind of curious.
Yeah, yeah. So Firebase implements Remix if you want to, but but yeah, offline this is not, this is just managing slow networks and it it does a pretty darn good job of it, I must say. So. Now we just need to start using quick. Have mish go on and put quick with remix. We'll be all set. Yeah, that would be really interesting. I I have opinions about all of this. I'm not.
Whoa. Oh. Inception. Yeah. I I. Like opinions? Yeah, I I'm still unconvinced that we're chasing the biggest bang for our buck here with with this stuff. I feel like you get a lot more headway on key metrics for most apps if you focus on on just making the server faster. And a lot of people have are are like.
Even if it is that like on a, a slow device. So like for example, stop just client rendering and, and bring in a server you like that will make the user experience way better. And then when, when you get to the server rendering, now with React, we've got the streaming API and that has some really, really awesome capabilities with it. That that is partial hydration, by the way, selective hydration as well.
It's so, yeah, a lot of the things that are being worked on, I think it are good that they're being worked on, but it I am still not convinced that it's going to make that much of a difference for most people. So we shall see. I I welcome them to rebuild like like we did with Next JSI, welcome them to rebuild one of our demos in their thing and show us the actual metrics of how it's faster.
I do have to say I really enjoy those comparisons, like where you actually build an app and you show it in different frameworks. I like those, yeah. I love the back and forth too, because like, I haven't worked with a lot of those guys. It's, it's very interesting to see like opinions on one side and opinions on the other.
And then just raw comparisons from like like Ryan Carnegato and and. Those I was going to say that Solid and quick and Remix have like made these conversations like come to the forefront and starting these are like the way to evolve the web to a better place. Yeah, I I think that Remix is really on to something here with the the focus on the web platform and just creating an amazing developer experience. We didn't get time to talk about streaming and the new deferred API that's coming up in the next week or two with Remix, but like that will really take things to the next level. Unfortunately, there are limited hosts that will stream for you, so anybody built on top of AWS will not stream. So you cannot use Reactive Teen streaming on top of AWS. Luckily Netlify just released the Edge functions with Dino and Dino does support streaming, so that's exciting really. Interesting because Versailles is all AWS, right? Yeah, so Versal also just
released a while ago their their edge functions which is wrapping Cloudflare and Cloudflare supports streaming, so. I guess when you get to the edge like that it can really change. Yeah. Like the lambdas and stuff are what are underneath. I think Nellify runs on AWS Lambda too for. The serverless functions do, but the edge functions run on D note.
Yeah. So that's interesting. Yeah. So just your. Hiccups. Just not. Not every app needs streaming because like it. And the only time you need streaming is when your back ends are slow. Like you're hitting some back end that is slow for some reason. And there are, there are good reasons where you couldn't speed things up, like you're doing some computation that just like it. It's hard to make this computation fast. It's impossible to cache it or whatever, but that's that's the only time we're streaming.
Actually is useful. Otherwise you just, you know, do a regular HTML render and you're like 150 milliseconds and it's fine. Let me ask you something too about this. If if we have this app deployed to fly to IO, that's a single server in one location, right? It's not like a. CD. That's the way that the Indy stack is configured, but the Bluestack is configured to be able to deploy it to multiple regions, and they have something like 35 regions all over the world. And so you could deploy it to multiple of those, not just one, OK.
And and so that's what I was going to get to is that deploying to the edge, what is the time difference? Would that be faster than having that single server location? Yeah, it probably would it. So these are things to really measure. But the what's what's cool about Fly in particular is that because they have all those regions all over the world, whether or not you've deployed to that region, the user wherever they are, they're going to go to the region that's closest to them, whether or not your app is there. And then from that region, it will stay on Fly's network and and go bounces.
Yeah, it bounces around to get to the region where your app is deployed. That network is like really fast. And so it's it's much better than the user having to go through their own, you know, whatever infrastructure their ISP has to to get to that. And maybe some of that infrastructure will actually be shared. But but yeah, for whatever that is, the fly infrastructure will will get it there probably faster. And so that's that's one cool thing is even if you don't leverage the multi region support, you're still in a pretty good place from that perspective. But yeah, like if you're going from Hong Kong to Virginia, US East or something, then yeah, you're there is definitely some latency there.
And so deploying to the edge does matter if like 100 milliseconds means millions of dollars for you, right? Yeah, Where e-commerce? That's e-commerce hats, yeah, yeah. So for for those use cases, deploying to multiple regions is really nice. And and FLY also with with the Bluestack, it's configured with Postgres and fly supports Postgres cluster.
So it'll automatically propagate changes to all of the other databases within like 200 milliseconds or less. When a change is made to the primary, it goes to all the other ones really pretty quick. And so and, and actually the other thing is you could, one concern that people have is, you know, the GDPR stuff where data has to be stored in the country where the user's at or whatever. So you can, you can do that with fly as well, which is kind of interesting.
But yeah, to point to the edge, it matters for some people, for others it really like if it's a matter of 500 millisecond difference, then it probably is not a huge deal. Nice, cool. I think we could probably pick Kent's brain all day long on remix, but it really makes me want to try more of it now, though, just to at least understand and be knowledgeable on on kind of more questions to ask. I keep thinking about like we I feel like we've rewritten coding Kat a million times over back end, front end. And we were talking about like spelt kit, but spelt kit, we're having a lot of issue.
Yeah, Steltkate is just going through a lot of API changes right now. It's coming up to one point O and they're just, they're doing a lot of API changes that are a little frustrating for the users right now, but we'll get through it. There's another big one coming that Rich posted about today. It's causing some uproar in the community. I I feel like the the biggest thing for me though is still React and frustrations with React. Do you find that there's less of that with Remix? Oh yeah.
Especially with state management. Yeah, the frustrations that people have with React don't really just. Just today, like I can see it here, like I am very outspoken, not really a fan of React and they know this on the show. Sorry, but this developer experience is much better and makes me feel better about using React and JSXI can deal with this.
Yeah. Well, and one of our employees who's working on the router, one of the the big reasons that he is so excited about it is because he actually prefers view. And so he's absolutely going to be building a View version of Remix. And so and, and again, Austin was working on the spell router for Remix and, and so there could be a spell version of Remix. And we're, we are actively doing work on some other things to make it easier to integrate remix with other build tools and and other things as well.
I don't want to talk too much about that because we haven't shipped anything. We tried to avoid talking about stuff we haven't shipped yet, but but yeah, so look forward to things. If you started with React today with, with Remix today and started doing React then in a couple of months, if probably by that time we'd support other frameworks. It wouldn't be like a lot of work to switch. Like it's literally just the the UI like how you render HTML. So that's not very complicated to switch from JSX to, you know, whatever else you want to use templates. Yeah, it sounds like a lot of a lot of exciting things are coming in the pipeline.
Maybe I could go back to my Angular routes and still use Remix somehow? That'd be. Kind of, yeah. I mean somebody put together an Angular router with a Remix router, so if you want. To Austin is doing a talk on the remix router spelt at spelt Summit. And I'm just, I'm really excited to, I see that. Oh.
Awesome. Super exciting. That'll be sweet. I think that's probably it for Remix. I know B1 Mind has more questions on optimistic UI. Hopefully hit us up in the learn buildings. Yeah, actually you know what I did? I gave a talk that went into optimistic UI quite a bit. So let me find a link to that and I'll put it in the whatever chat thing I was also.
Thanks so much for for coming on. I if if I can like pin you right now since you're on live, will you come back on once we learn more and can kind of ask you harder questions? Yeah, yeah, I'd love to come back and and dive in deeper. Like so far we've done like what can you do without JavaScript? I'd like to talk about, OK, now we have JavaScript on the page. What JavaScript does it take to make this experience even better than just what the browser can do? Oh.
