69: The Suspense is Almost Over — A Pre-ReactConf Concurrent React Rundown with Swyx
This week is React Conf!
And I suspect that Suspense and Concurrent Mode will have a good showing.
So — in anticipation and excitement — I asked friend of the show, Swyx, to join me for a Suspense/Concurrent React rundown episode — covering everything you need to know so far and what we hope to see at this year's event.
Neither of us have priviliged info.
We're just two nerds who like to keep abreast of React's most exciting future feature.
Featuring
Links
- STAR Apps: A New Generation of Front-End Tooling for Development Workflows on CSS-TRICKS
- STAR Apps at SV Code Camp by Swyx
- JAMStack — A modern architecture —
Create fast and secure sites and dynamic apps with JavaScript, APIs, and prerendered Markup, served without web servers - Beyond React 16 | JSConf Iceland 2018 Dan Abramov's introduction to Async React (eventually Concurrent React) at JSConf Iceland 2018
- Fiber Reconciler doc on reactjs.org
- React Fiber Architecture — a gist by Andrew Clark
- A Cartoon Intro to Fiber — a talk by Lin Clark at React Conf 2017
- Dan's Tweet on ConcurrentMode and how it informs other React APIs
- Building The New Facebook With React and Relay — an upcoming talk by Frank Yan and Ashley Watkins on Building The New Facebook With React and Relay
- Building the New Facebook.com with React, GraphQL and Relay — talk at F8 2019 about facebook.com v2
- Relay — A JavaScript framework for building data-driven React applications
- Apollo Client — A complete state management library for JavaScript apps
- URQL — Universal React Query Library is a blazing-fast GraphQL client, exposed as a set of ReactJS components
- Getting Closure on Hooks — Swyx demonstrating a simple mental model for hooks at JSConf.Asia 2019
- [Umbrello]React Flare — GitHub issue for tracking the React DOM implementation of the experimental React Events API
- React Fire: Modernizing React DOM — GitHub issue for tracking React DOM modernization
- React Native for Web — Run React Native components and APIs on the web using React DOM. A library by Nicolas Gallagher
- Dominic Gannaway — React Core team member working on React Flare and React Fire
- The Case for React Native Web Singularity A post by Swyx on React Native for Web as a template for a future React developer experience
- SVELTE — Cybernetically enhanced web apps
- glimmer — Fast and light-weight UI components for the web
With the attention to detail you've come to expect from Ember - All you need to know about Ivy, The new Angular engine! — An article that seems to suggest it has everything you need to know about a thing I know nothing about
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
G2i
G2i is a hiring platform for remote developers devoted exclusively to React and React Native. We vet, you get hired. g2i.co
Transcript
[00:00:00] Michael Chan: This is React Podcast. I'm Chantastic. Hey, React nerds. This week is React Conf. And I suspect the Suspense and Concurrent Mode will have a great showing. So, in anticipation and excitement, I asked friend of the show Swyx to join me for a Suspense Concurrent Mode rundown episode. Uh, talking about every everything that we know uh so far and what we hope to see at this year's event. Now, we don't have any privileged information. We're just two nerds who like to keep abreast of React's most exciting future feature. This week is made possible by Infinite Red and G2i. Infinite Red builds beautiful, functional apps in React Native. And they want to help you bring your ideas to life. Use their expertise in design, mobile, React Native, Ruby on Rails, Node, Phoenix, and Elixir to get your app on track. For a limited time, React Podcast listeners get 2 tickets to Infinite Red's Chain React Conf when they start a new project. Chain React is North America's only React Native conference, and attendees are saying it's the friendliest, most educational conference they've ever been to. At the conference, you'll get to meet the team and see why they're the React Native industry experts to take your app the distance. To start a project, go to our very special URL, reactpodcast.infinite.red, and get 2 tickets to Chain React Conf 2020. Build a beautiful, functional React Native app with Infinite Red. Now, for me, the worst part of contracting by far was shoring up and maintaining business. I never wanted to interrupt a good coding bender to take a sales call and send off invoices. I just wanted to do the work, getting critical features into customers' hands. G2i makes that possible. They market you and your skills directly to companies. They manage all logistics, contracts, invoicing, and payments. You get personal support from their incredible team, so no previous contracting experience is required. And best of all, you join a unique collective of incredible React and React Native developers available in Slack to help you through those really tricky moments. So growing your skills is integrated into a day's work. If you're a contractor, don't go it alone. Partner with the amazing people at G2i. Go to g2i.co today, apply, and find opportunities you'll love. G2i. We vet, you get hired. It's that simple. All right. Swyx, welcome back to React Podcast.
[00:02:59] swyx: Hey, thanks for having me back.
[00:03:00] Michael Chan: I'm uh I'm excited to have you back. Uh we uh we I think over the last like year and a half maybe, we've developed kind of like a conversation around uh uh uh concurrent mode and Suspense. I think we were both kind of like into it, like into that the notion of it when when we saw it. And we've just been like super excited about it. And we we kind of talked on YouTube once about it and all this stuff. And Like every time we get together, we kind of like, like Crazy Rich Asians, Crazy React Asians is our- React Asians. Yeah, not rich. Crazy React Asians is kind of like our mantra. And we've just been talking about this suspense thing for like a little bit over a year. And I thought going into React Conf 2019, it's next week, it'll probably be like the day of or like the day after we air this. It's gonna be pretty heavy, I assume, on a lot of like concurrent mode uh stuff. So, I thought it'd be fun to just kind of get you on and talk about like what you're excited about, uh what you think might get released, uh kind of some of the changes that we've seen over the last year in concurrent mode and uh all that stuff. So, um so so first of all, where are you? What you been up to this uh this week?
[00:04:14] swyx: Uh wow, that question is very loaded for me. I'm in I'm in a random coworking space in San Francisco. in the Tenderloin, which is always a fun place to be in San Francisco. I have been doing a bunch of conferences. It's conference season this this week, this entire month, basically. So, just been doing a bunch of talks around the Jamstack, around Star Apps, which is which are which are these uh bunch of investment theses around the frontend ecosystem. Um and yeah, I mean, just just doing a doing a doing a bunch of conferences and and public speaking. Um Netlify, ourselves, we had a conference this week and we launched a bunch of new things and it was just a really good time to see the company because I live out of New York. Um, so it's not so often that I come to San Francisco and see my coworkers.
[00:05:07] Michael Chan: Yeah, that's awesome. How was uh how was Jamstack Conf?
[00:05:09] swyx: Uh, yeah, it was really good. Like surprisingly good. Like we we actually, so we actually had this new thing where um we asked people like if they were gonna launch things to launch them in like lightning launches. So we actually had uh several different launches scheduled. Uh, quite a few of them were like CMS-y, like WYSIWYG type things, and and it seems like the like people are very interested in the no-code space. Like in this in this week alone, um there have been multiple VC investments in headless CMSs.
[00:05:39] Michael Chan: Wow.
[00:05:39] swyx: Which are CMSs which which are decoupled from the front end, so you can write your React uh uh front end you know front end with Gatsby or whatever other static site generators, or or you don't have to use React, but the idea is that you edit uh your content in a headless way, And that's that's a that's a pretty interesting thing. Like I didn't I didn't anticipate so much VC money going in. It was like a 30 million Series A, like a 4 million thing for uh for Sanity.io. Like um and and and just like a bunch of other uh companies are getting funded in this space. So it's pretty exciting.
[00:06:12] Michael Chan: Nice. Well, I know I've been familiar with a a project a product I think called uh Forestry. I think they've been in this space for a while. And it actually like it's a front end But then it actually makes Git commits for you. Is that right?
[00:06:25] swyx: Yep, yep. Totally.
[00:06:26] Michael Chan: Which is just so cool.
[00:06:27] swyx: And and so Forestry was one of the teams that launched something this this uh conference uh called Tina. Um I haven't played around with it. It seems like it's like a visual editor for uh with with React components. Uh that's as much as I know right now.
[00:06:42] Michael Chan: That's awesome. That's awesome. That's gotta be super fun. I know that you know you're you're at a Working at Netlify, I mean, you're like at the center of like a very cool thing that's happening right now. And so seeing all this this work happen in this space is awesome. It must be fun to actually be at that conference.
[00:06:58] swyx: Yeah. Yeah. And as part of my job, you know, I I I'm I'm sort of encouraged to keep on top of uh React stuff. And and that's why, you know, I I get to squeeze in a little bit of um React community work, um keeping up on React news uh as part of my job just to just to keep refreshed. And do talks on it.
[00:07:14] Michael Chan: Yeah. Well, hey, real quick, um, I mean, we could do a whole episode on this, but you mentioned Star and I saw a bunch of tweets about it. Could you just give us like the the elevator pitch on that? And then that'll just be like a little teaser for the next time we get together.
[00:07:28] swyx: Oh, sure, sure. Um, I think it was just like a mental framework for like what uh people are investing in. Like, it seems like as the backend becomes more and more commoditized, um, and everything moves towards uh platform as a service, serverless, Uh being being much uh easier and easier. Uh the engineering efforts are moving towards the front end where uh the more the business value is created uh by working on things that uh working on products more than platforms. Um and and so um the the things that people are investing in, like when you hear about uh the New York Times moving to React and GraphQL, when you hear about Airbnb moving to TypeScript, uh when you hear about everybody on earth um open sourcing their design system, What is the common trends and why are people making the architectural changes that they make? And what are the trade-offs to those things? So I kind of grouped them into design systems, static typing, smarter APIs, and static or client-side rendering. And so and so those are those are exemplified by 4 technologies. They're not specific to 4 technologies, but they're exemplified by Storybook, TypeScript, uh Apollo GraphQL and React. Um and so uh it started as more of a silly acronym that uh I I was just like noticing that these things came up again and again and again. Um so I wrote an article for on CSS-Tricks. Um Chris Coyier like gave me a lot of um uh um confidence by like also fleshing it out fleshing out the thesis uh with his talk uh at Jamstack Conf.
[00:08:55] Michael Chan: Awesome.
[00:08:55] swyx: Um so I I highly recommend uh checking that out.
[00:08:58] Michael Chan: Yeah, we'll have to— um hopefully they'll come out and we can link them and and whatnot.
[00:09:03] swyx: Yeah, you should have Chris Coyier on on the pod, actually. I think he's I mean, obviously, he's very deep on frontend. Um, but CodePen CodePen itself is also going through this this uh evolution, and I think it's a pretty interesting thing to talk about.
[00:09:16] Michael Chan: Nice. Yeah, I I I'd love to. He's he's he's definitely on the list. I feel like I kind of need to make this like a I mean, if I could handle it, I would make it like a twice-weekly show because there's so many cool people doing so much cool stuff.
[00:09:29] swyx: For sure.
[00:09:30] Michael Chan: So into the into the meat of what we want to talk about today is uh is Suspense and concurrent mode and React cache and all of these things that kind of like tie into uh tie into one another. There's like a big bucket of stuff that's kind of been on the horizon a little bit. Um so maybe we should just start at like first first principles, right? Like so what is Like, what is like Suspense or I guess concurrent mode? Like, we have some of it already, but like what have we- what are we not seeing? What are some of the things that we've seen? But, you know, just a bunch of questions. So, where do you want to start?
[00:10:12] swyx: I mean, I think I think I should hear from you because you just taught a workshop on this. Um, so, this is more of a discussion rather than- like neither of us are experts, neither of us are in the core team.
[00:10:22] Michael Chan: Definitely not.
[00:10:23] swyx: We don't represent them. So we we just kind of followed it close more closely than some. And and so we're just kind of piecing together the the pieces. Um so I'll fill in from the historical perspective and then maybe you can talk about uh where we are at right now. Um so uh so essentially Suspense was announced uh March of last year um at JSConf Iceland. Um and it's October 2019, so it's almost it's a year and a bit since uh since it was announced. So they're definitely keeping us in suspense. Um I don't know if that was the intention, but. Yeah.
[00:10:56] Michael Chan: They named it appropriately if that if that was.
[00:10:59] swyx: Exactly, exactly. It works on it works if you're blocked by a 7-person core team. Um, so, so so it was initially called uh Async React. Uh and and the and the idea was that everything used to be synchronous synchronously rendered. Um, that that meant that you not only were blocked um when you're doing expensive work, um you would also have to manually implement uh loading spinners and and and and and and common UI patterns, um just to um unblock your your synchronous work or to to chunk up your synchronous work. Um and so they they wanted to make that a first-class um sort of API inside of React. And to make that to make a lot of that imperative code which uses state, which uses life cycles, um and just make that declarative by just wrapping things in a thing.
[00:11:52] Michael Chan: Mm-hmm.
[00:11:53] swyx: in a wrapper called Suspense. It doesn't have any corresponding element on the DOM, but it but it's an instruction to React that, hey, like this is a boundary at which you can suspend everything inside it for data fetching, and you can show a fallback. You can uh you can it has a priority at which um you know that fallback shows. Um and I think that's a that's a very key part of it because there are a lot of people who try to replicate the API of Suspense, which is essentially a read from a cache. Um and you can absolutely do that um without React Fiber, you can do that in user land. But what you can't do is do the temporary like timeout, like like like the not like so what what one of the key features of Suspense is that it uh actually waits for a bit before it shows the spinner. Um and And if your if your async fetching resolves before that thing, uh before that timeout, um then it doesn't show a spinner at all. So that involves some pretty complex coordination logic, which obviously you could do yourself, but um React is sort of building it in for you. Does that help? Does does would you make any changes to that? That's my sort of summary of the high level.
[00:13:09] Michael Chan: No, no, no. Yeah, I think that that's I I I think that's that's that's great. And I think that that really well summarizes all of the things that we saw in that March event. from Dan and kind of the high-level, like, uh I guess, goals for this. Now, like, I guess uh one thing to clarify is like this was like pre-hooks. This was, you know, pre— you know, like you you talked about like uh the the name change to to concurrent mode. It was kind of the first thing that we saw with uh like op or utilizing the Fiber architecture. And if I'm not mistaken, this was pre like scheduler. Like we hadn't seen anything about like the,
[00:13:46] swyx: you
[00:13:47] Michael Chan: know, scheduler at that point.
[00:13:48] swyx: Right. Um, I think the scheduler was almost uh immediately split out because they they realized that there was an opportunity to collaborate with other frameworks to do that. Um, but yes, um, when it was introduced, uh this uh Suspense was introduced together with time slicing, which is a confusing- like it's a feature, but not a API. Um, yeah. But it also kind of is an API. It just like is called a different name. So so uh that that that bit is a little bit confusing, um but I think where it's resolved to, so it used to be called Async React and now it's called Concurrent React uh because they they felt that that better conveys the the idea that there's a work-in-process thread and then there's a uh currently committed thread. Um and so and so uh like the the whole idea is that if you opt in to a concurrent route, um then then everything inside of that root would be um would be time-sliced for you. So so React Fiber is doing the time slicing for you. Um I I also want to make that make a mention that the first actually the the first uh we've we've been seeing benefits from React Fiber rewrite ever since React 16.0, um with uh fragments, um with like array return values. Yes. So so we uh we've we've been seeing You know, small things. Uh, but this is this definitely the bigger uh one of the bigger um implications of React Fiber.
[00:15:10] Michael Chan: Yeah. So, if I understand correctly, like right now as it stands, when you render a React app, it kind of, you know, in like, you know, I guess what could be called like sync mode now. Like you— um, is that is that what we're calling it? Like, you know, now that there's another thing, is it is there a name for the thing that's always been? Or how does that work?
[00:15:28] swyx: That's an interesting question. Um, I don't I don't know yet. I mean, there there I don't think there is a name. It's just it's just what was you know what we have before.
[00:15:37] Michael Chan: What was before.
[00:15:38] swyx: Um, because because right now, what we do is ReactDOM.render, right? Um, and that creates a synchronous root. And and actually, what um will change to what it will change to is a ReactDOM.createRoot API.
[00:15:51] Michael Chan: And and the difference is that, if I understand correctly, right now we we render basically the whole thing. Like gets rendered into the like you know, virtual DOM or whatever. Um, and then that gets diffed into the actual DOM, right? But like in concurrent React, now there's ways to like kind of like update just single parts of it. Is that is that the big difference?
[00:16:13] swyx: Oh, um, I I don't I I don't I would never— uh I I I wouldn't use those exact words.
[00:16:20] Michael Chan: Yeah, no, no. I I I'm I I I am very uh not knowledgeable in this space. So yeah.
[00:16:27] swyx: So the the the sort of definitive resource for understanding Fiber is um Andrew Clark's repo. Uh we can definitely link that up in uh the show notes, um as well as Lynn Clark's. It feels like you need to have a last name of Clark to to to get this, but um Lynn Clark's uh talk at React Conf, I think 3 years ago. Um and so and so I think the idea is that uh the the Stack Reconciler used to have everything on one one stack, And there was no other way around it. And Fiber made every component into a data structure, which is a linked list, which you can traverse pretty freely. But then also every Fiber has a work-in-process version and a currently committed version. And you just sort of double buffer and commit back and forth between them. Interesting. And so the idea is that you can still stay interactive on the currently rendered Fiber while React is still working on the um work-in-process Fiber that that has not been rendered yet. Um and so uh because reconciliation uh reconciliation is expensive, this is the kind of thing that Rich Harris calls um amortizing the cost of rendering. Like because uh you know you're you're you're doing all that work in in uh diffing the virtual DOM, um let's just put that in the work-in-process thread. Let's let's let us be able to start and resume that every 16 milliseconds. And meanwhile, everything that's currently that we're currently rendering on screen stays interactive all the way through. So if you remember that lag radar that was on the JSConf Iceland video, that is possible because everything that is being done in the background is on the working process fiber, so we don't actually have to commit that. We can just start and stop that. So that's something that the stack reconciler was not not able to do because it was just- Done all in one swoop.
[00:18:18] Michael Chan: Interesting, interesting. Okay. So, so we have ReactDOM.render, which is the way we have it now. And the way React apps have have have worked up to this point. Even though we have the like rearchitecture of Fiber, like it's still kind of like all operating in this like, you know, synchronous synchronous mode in terms of like rendering. But kind of our opening into concurrent mode is this new like createRoot API. Unstable right now. So marked unstable. But uh eventually maybe a createRoot API which renders things differently. Now, I know that that has an effect on the way children are rendered. Is that is that right? Or the way that they're rendered kind of I guess together or separately?
[00:18:58] swyx: Yep. So it does it does change the defaults to render um render siblings together. Um in fact, I I gave one of one of my earliest talks on this, I gave uh talking about React's new defaults. Um and that this is a this is a little bit of a paradigm shift in in the sense that Um, even uh and and so even if one of the children is uh going to be uh going to need data to to be loaded, um, all you got to do is is suspend within that that child and the sibling of that child will also suspend together with it even though it it doesn't have that that data requirements. Or or or you don't have to like manually sort of coordinate that with by lifting state up and then doing like, you know, if it's if it's updated then render both of these.
[00:19:39] Michael Chan: Gotcha.
[00:19:40] swyx: So they so React just naturally coordinates uh the way that children uh suspend and and show together. Um and obviously, I think I think you're building up to this, that there is an API um to show to control even the reveal order of uh of these of these children. You want to talk about that?
[00:19:56] Michael Chan: Yeah, yeah, yeah. So, I guess let's uh I guess let's go just a little bit into the future. So, we had the so we had that that March event. And then uh React Conf last year, they talked a little bit more about what they were working on with Suspense. And at that point, uh let's see, so this was a year ago now at React Conf 2018 in you know October, I guess it was, uh where they released a Suspense component, which which we've been able to use all year to lazy load components. Uh it has the fallback as we we'd seen. Um but it didn't have uh what we'd seen before, which was like max duration and even prior to that, uh was it delay ms or for milliseconds or something like that.
[00:20:37] swyx: Yeah.
[00:20:37] Michael Chan: Where these the Suspense component actually controlled the amount of delay before it would present the fallback.
[00:20:43] swyx: Right.
[00:20:43] Michael Chan: And so, those were those were a couple of the- I think that was uh well, that and maybe React Cache and CreateResource. Those were kind of like the introductions at the point of uh at of React Conf 2018 last year. Is that about where we were at?
[00:20:57] swyx: Um, that's where we were at. Um, okay. And uh I think the the idea— and again, this is this is why um we could we could show the Suspense API without uh finalizing everything else, um was that um if we don't have if you don't have a duration or a max duration, um everything just falls back to a max duration of uh of nothing or-
[00:21:21] Michael Chan: Oh, sure.
[00:21:22] swyx: Because you're not in a concurrent root. Um and so and so it only starts to matter when you're in a concurrent root what the duration um is because then then then you actually have that double buffering scenario. Going on. Um, and so, um, I think I think one of the issues with that the React team has been struggling with is communicating what duration really means. Um, and and there and the idea is that there's this complex formula. It's not that complex, but you need to have it in your head that uh when you say Suspense.maxDuration of something, um, you're not really controlling, you don't really have that much control over what the actual duration is. Um, React still still decides for you. And you're just- all you're doing is just lowering the tolerance level from whatever the default is. And it seems like there's multiple levels of duration now. I don't even know. I've just like stopped keeping track of what the levels of priority are, but but they really want you to think in terms- instead, like stop thinking in terms of hard, like, you know, numbers in terms of duration and just think in terms of priority levels and then uh let React decide for you.
[00:22:26] Michael Chan: Interesting.
[00:22:27] swyx: So it's it's a little bit more of a a reach in terms of like— um I I I always think of these in like it's like you know in in that in the evergreen question of is React a framework? Uh React is becoming a little bit more of a framework in the sense that you're inverting control, you're giving React control over when exactly things render, um because React's uh you know you shouldn't you shouldn't have that fine-grained you know control, um otherwise Um, React, like, like you, yeah, I don't know how to put this, like React, React needs to understand when it's rendering. Um, and so it can control what it's rendering.
[00:22:59] Michael Chan: Well, I think that's, I think, and I'll put this in terms of, you know, people who've been listening to React podcasts for the past couple of of of months would understand is that, um, we had an episode, um, with Paul Henshaw talking about useSpring and he was talking about how in CSS you, you animate things by transitions and you give things like a, a duration, a effectively. He says, but that's not really how things animate in the real world. Like there's it's much more complex than that. And it's about the relationships of like this thing to the other. And like how what harmony feels like in inside of an environment. And it's less like, you know, get from here to there in 300 milliseconds. And I think that's a little bit kind of what we're like a transition that we're seeing. Like so we've seen this like delay in milliseconds and max duration. And it's kind of hard because that's not really the the intent that like we're after. Like in in React, the intent is like, hey, like all of these things are being being coordinated. Like what is your intent? Like how do you do you want people to see all of this all together? Like do you want to have control over when they— a little bit of control over when they see a spinner? Because like you know maybe it takes 100 milliseconds and it's just a flash when you know seeing a white page for 100 milliseconds until you saw actual content would have been you know, a better user experience. And thinking about those things from a much higher level in terms of like coordination and experience versus like, like, hey, wait for 250 milliseconds until this thing- until you show a spinner.
[00:24:30] swyx: Yeah, totally.
[00:24:31] Michael Chan: Does that seem kind of like accurate?
[00:24:33] swyx: Yeah, I agree with that.
[00:24:34] Michael Chan: So we- so I've noticed that in like a recent build, actually, like, so when I was using a Suspense component, um, you know, just recently, uh that that they have actually taken max duration off of of Suspense. And uh and so, that's like no longer no longer an API that we even have. Um so, what are some of the things that are kind of like coming in to maybe fill fill that gap that we might not know about now?
[00:25:01] swyx: It sounds like you're talking about the the new the two new hooks that are being introduced. Um and this is like As soon as this week. So uh obviously obviously the facebook.com rewrite um was done over the past year or so, and they've been using uh hooks in production at scale, uh hooks and Suspense in production uh at Facebook. So um what essentially is they're they're doing is they had a private closed source uh implementation and usage of this and they're testing it out and now they're sort of copying it over and open sourcing it. Um so it's it seems like the the the the key thing that they they're trying to do is is is based on this useTransition hook. And it's it's actually pretty analogous to the the loading um flag that Dan actually used in um the JSConf demo. Um but now it's a hook, so it's available anywhere within your app. Um and you can tap into the React runtime and actually see if like um you know see if like if if something is loading, then you actually show a spinner. But um you know the the whole thing about like not showing a spinner if if you don't need it. Um so It's kind of funny because Dan was kind of reflecting on this and saying that they didn't even have hooks in mind when they started talking about Suspense and concurrent mode, but it's as they sort of proceeded and explored the space, they found that hooks were a great API for this, and now they're now now they can't imagine not having it when using Suspense. Um, so it seems like it's a necessary part. And I mean, I I I just love the way that uh Dan explained it at React Conf last year when he introduced hooks. It really does seem like uh hooks were there all along, we just like were kind of going in to to like split the atom and like discovering the individual subatomic parts of like, "Ha, this is a state and we need to like expose that as a hook." And then this is an effect and we need to expose that as a hook. And and all these like individual parts and and now we now we split them up, we can tap into uh the runtime in a very flexible way. Um and so so so this is this is a new part of the component's responsibility, uh its role in the Suspense tree. Um and The way to tap into that is through one of these hooks, useTransition or deferredValue.
[00:27:10] Michael Chan: Interesting, interesting. So these would- now, so useTrans- so a lot of our hooks that we've seen so far are uh like just like globally useful. Um I I mean I wasn't able to gather this in my reading, but is this is useTransition effectively only gonna be useful in in a concurrent concurrently rendered app?
[00:27:30] swyx: It seems like it.
[00:27:30] Michael Chan: Yeah. It seems like it to me too, but I wasn't totally totally sure.
[00:27:34] swyx: I'm also not sure I'm also not sure about the name, by the way, because um A lot of people read it and assume it's for animation and it's not.
[00:27:40] Michael Chan: Yes.
[00:27:41] swyx: So that's ipso facto an indication of a bad name.
[00:27:45] Michael Chan: Yeah, I think that the the error, at least as I as I read it in, I I think the release of 16.10, if you put max duration on a Suspense component, uh it said read the docs for useSuspenseTransition. Um so maybe there's some maybe there's some kind of like ongoing discussion about what that API will eventually be.
[00:28:07] swyx: Yeah, so like in the PR, Sebastian actually said like this is only useful within a Suspense anyway, so he just dropped the Suspense word from that hook name, but now it just reads wrong. Like now it just reads- Naming things is hard. I'm sure they'll figure it out.
[00:28:21] Michael Chan: It is.
[00:28:22] swyx: It's it's pretty funny. Like there was this- I actually recommend people interested in in like naming things, uh Sophie Elford actually talked a little bit about, uh they had like 100 candidate names for hooks And like, you know, everything, like fix-ins was like the other popular one, which I like a lot. Like mixin, fix-ins.
[00:28:41] Michael Chan: That's still my favorite, fix-ins.
[00:28:43] swyx: I mean, I, you know, there's there's a strong argument for that. But they wanted— um, the the React team prioritizes short names uh for APIs that you're gonna use often. Um, and despite hooks possibly being confusing with uh other usages of the word hooks, they they preferred that because That's just like something that we're gonna use again and again, so you obviously want something intuitively and short, easy to remember. And this is this is a very interesting shift compared to the way they named lifecycle methods, which were like, let's make it as long as possible, component will, whatever. Um and in their own code, they they prefer long names, but it's interesting shift in API design when uh when they when they think about uh you know public APIs.
[00:29:28] Michael Chan: Yeah. I remember in uh in our React podcast episode with the core team last year, um uh Sebastian said that he he will always think of them as augmenters.
[00:29:39] swyx: Terrible.
[00:29:42] Michael Chan: Which I can't- can you imagine? Like I feel like maybe they wouldn't have even taken off if they were augmenters. I'm sure that it is a perfectly accurate name. But I I can't- I I don't even think I know how to spell augmenters.
[00:29:55] swyx: It's it's kind of like me whenever I like There's some like transducers in Redux land and I just, my brain just turns off. Um, so,
[00:30:04] Michael Chan: yeah,
[00:30:05] swyx: yeah. Name, name, on one hand, name, naming doesn't matter because it just compiles down to code. On the other hand, name does matter because it's, we read code more than we write code.
[00:30:13] Michael Chan: Yeah.
[00:30:14] swyx: And and code is code is actually for humans uh to read as well.
[00:30:17] Michael Chan: Yeah. And it's like how we, how we talk about it, how we have conversations about it and how easy those things are to say really does matter for those conversations. So yeah, so we have we have these two uh these two new hooks. And it looks like useTransition or useSuspenseTransition or whatever it ends up being is going to be maybe the way that we uh manage those uh transitions of Suspense elements, kind of replacing what we'd seen before in the theoretical like max duration and delay milliseconds that kind of preceded it. Um and you bring up an interesting point. And I think you had mentioned before we started, like there was a conversation or um A Twitter conversation that Dan started about how- like why they've taken this this this course of kind of announcing suspend um suspense or concurrent mode or async mode so long ago, um but then kind of like not having like publicly available uh ways of using it, um is is that there's all these things that like came out of it. And you talked about like kind of like breaking down the atom, breaking down the component into like hooks And like all of these things have kind of like come out of this vision for the future, um that in in support of that vision and like are kind of informing the future of that API. But it's it's really like a slow process figuring that out.
[00:31:34] swyx: Yeah, it's a you know it's a ton of R&D and it's uh it's really amazing how how uh I mean I'm sure there's a lot that we that we just don't see. But it's really amazing how uh you know It's a it's a it's a very sensitive process of like, if you if you talk about things too early, you might kill it because you might you might get a lot of uh negative feedback on immature ideas that just need to just need some time to to try out. Um and so and so I think one one of the reasons why they opted for this, because there's this debate, uh it's affecting Vue as well and and and some other uh frameworks where like, when you say open source, how much is open? How much of your your your roadmap is open? Hooks were not open uh and and and um to to to a great deal, and and like and and this kind of went against the print the grain of how React adopted an RFC process. And I think people were uh sort of assuming by that that everything would start as an RFC and that would be the first um instance of any public discussion of anything. Um and it it turns out that that's not the right way to launch uh something. Yeah. And so and so for uh for React's uh concurrent mode in particular, uh it seems like what what Dan is saying over here is that um it requires a lot of buy-in from the ecosystem. Like um it seems like uh there are some things in uh in the in in the React ecosystem that don't really jive very well, at least in mental model, but maybe in API, uh with the uh the idea that there's a work-in-process thread and then there's a there's a ongoing, like like like there'd be multiple accesses to a single source of truth. That if it's not in React and React doesn't know about it, then it might cause tearing of state. And so so so he in his judgment, which like I I frankly I I don't see everything that he says, so I don't really understand it uh from from fully for what he's saying, but in his judgment, announcing it uh in March of last year um gave the ecosystem enough time to actually move significantly enough to where it's concurrent-ready.
[00:33:43] Michael Chan: Gotcha, yep, yep.
[00:33:45] swyx: I think I think a lot of it has to do with hooks because hooks are much much better uh aligned aligned in terms of mental model uh with the idea that uh you know each this is very functional. Each of these should be idempotent renderers uh with with uh controlled effects that that are tracked through a dependency array. Um and that's that's a much uh easier model than a class component with a single instance. Uh now to be clear, both of these match the same map to the same thing. in terms of Fiber, and you can probably use class components in your Suspense tree. It's it's just a better API if you do it through hooks. That's at least the the public line. I think there are reasonable questioning of of this, and I I probably am not stating stating it as best as I as I as I could be. But I think that's the overall thrust of what the argument is, that they they wanted to move the ecosystem towards a more concurrent-ready model. In their judgment, it has been a success. And that's why they took this unusual step.
[00:34:45] Michael Chan: Yeah. You know, that's one thing I love about it. I feel like they've done a great job of managing this project and managing that tension of it needing to be something that, you know, supports the use cases of of of Facebook, obviously. You know, they're the ones that are kind of paying the core team to like actually like keep working on this stuff. But then also it has a huge uh responsibility to the rest of the ecosystem who's like, you know, built their applications on on top of it. And I feel like this path that they've taken where they talk about what they're thinking is, reveal their thinking, and then just kind of like slowly work, slowly and methodically work toward it is um is great. And I know that I've seen this in in in really good um educators. Uh they're not afraid to let uh let the students be like just one step ahead of them, right? Like they'll tell them something, say something that's like, gives them an opportunity to think about what the next steps are. And then those questions like lead to like, you know, like the next lesson. And they're like, oh, yeah, great. Like you're thinking. And like this is this is where we need to be. And like React has always done a great job of letting the— I feel the community kind of be like maybe one step ahead and like putting those libraries out and exploring the like the space and the tension. And then being like, hey, all these are great ideas. Now we're gonna wrap that into, you know, now we're gonna wrap that up, package it up as, you know,
[00:36:04] swyx: In fact, like, uh, that's why I'm always in support of early adopters. Like, like you and I are early adopters. We, we actually care about this a lot. Most, like 90% of React developers don't know what about, about anything. They're still learning about hooks. They haven't tried hooks yet. When you, when you go to a conference and you, you ask like if everyone has used hooks or not, um, to you and me, like obviously we use them on the first day, but a lot of them just like, you know, they, they, they have bigger things to do than try new APIs.
[00:36:33] Michael Chan: So yeah. Those classes make money, man.
[00:36:37] swyx: But like, people have to burn their, burn their, get burned on on on on these new things to figure out the bad patterns before it spreads out to the millions of React developers out there. Um, so I'm always in favor of like, you know, the the the the early adopters trying things out, giving feedback. I think uh the the React community listens to those to that feedback very well. So,
[00:36:58] Michael Chan: yeah.
[00:36:58] swyx: Um, I mean, it's it's it that's that's a that's a that's a that's a nice way to manage the community, I guess. I don't have a thesis behind this.
[00:37:06] Michael Chan: No, no, I think I I think it's true. And I think that you know when you're moving so many people, you know, it does take— you know, I always say like it it you know it it when we're thinking about bigger features at work, I always say like it takes 2 years to do anything, right? And I think that that's the same for like open source stuff, right? Like you know they introduced hooks you know last last year. And I think that we still have another year until You know, people are like, oh yeah, like I get this, I understand it. It's my first, you know, solution, you know, it's my first plan of attack when I want to like build a thing, um, you know, where most React developers are actually in that space. Um, so I, I don't know. I, I like the slow approach. I think it's good for communities.
[00:37:46] swyx: One thing, one thing I, I would also mention, I think, I think, uh, just to sort of wrap this up in terms of, um, API exploration, um, is that in, in actual, if you, if you check out the old React, uh, React cache API and the way you do like a create resource. And then you do like a resource.read. Um, and and it's hard to mouth code on a podcast, but I guess that's that's what you do here. Um, but but you're you're you're sort of like reading synchronously reading within your render, right, uh this this this cache, and and that kicks off an async function, and that suspends, and then and then it resolves, and then you get back the value. And then you keep writing you keep writing as though it's synchronous, right? Yeah. It converts an async thing into a synchronous thing. And a bunch of other uh uh APIs do this, but this is a this is an as if you think about it, this is actually an asynchronous version of what the same thing you're doing in uh hooks. So essentially like React cache and and Suspense are are like the async version, whereas uh uh of hooks where hooks are synchronous uh synchronously tapping into the React runtime and then uh caches and Suspense are asynchronous tapping into anything outside the React runtime. So if you look at it on on a as I'm sure this was not planned, uh maybe like maybe only Sebastian was like, he was like, you know, as as when he was like a 12-year-old baby, uh he like already figured this out and now we're just working through it. Um but like, um you know, there's a very nice parallel between the way that we're using hooks right now and and the way that we will be using uh some sort of, some version of caches or resources, um, or Apollo, uh, queries. Um, they're all sort of like synchronously reading within the render. Um, and it's, it's a very nice, it's a very nice way to evolve the ecosystem. Um,
[00:39:36] Michael Chan: yeah.
[00:39:36] swyx: And yeah, I mean, I, I think, I think, I think that slow evolution definitely has prepared us to do a lot more inside of the render and that therefore everything can just be a function. Every component can just be a function.
[00:39:46] Michael Chan: Yeah. I mean, I couldn't agree more because it feels like You know, last year, like over the course of the last year, it feels like the story was, you know, anything that you've been able to do inside of a render prop or a higher-order component, you can now do inside of a hook. It doesn't mean you have to, but it means that now there's a first-class kind of, you know, thing for doing for doing that. And it changed the way that we we wrote that code. And it feels like now instead of, you know, It seems like now fetching data could just fall in line with like what we've seen with hooks, which feels like what you're saying, right? Is is that now this just feels like the next the next thing, right? Like, oh, we already know that, you know, how to get data from hooks like asynchronously, but in like a synchronous looking manner. And so now we're gonna do that same thing. We're just gonna- now these things just get data. And um that's- I mean, that that transition has been so uh smooth where it could have been very rough.
[00:40:44] swyx: Yeah, it's uh it I I think I think that it it stems from- okay, so there's another document that's like that's like foundational to understanding React that I think I wish everyone would would see is is uh is I think it's called React Basic, where uh it's it's basically just a gist, but it's it's it's in a GitHub uh repo. And it's just a a progressive step through of Sebastian explaining how he views uh React as a language. Dan Abramov has uh probably a more accessible version of this in his post. It's called React as a UI Runtime. Um and it and it basically just talks about React as a language, um and and the runtime interpreting the language um on on the fly and and doing things with it. And that's why uh we we're able to to do things like tapping into hooks and um and and and then, you know, calling Suspense and calling like Fragments and and and all this wonderful stuff. It really frees up React to do a lot more than execute things in order. And so it's becoming more and more of a runtime interpretation of React the language, which is pretty exciting.
[00:41:48] Michael Chan: I love it. So there's um and we'll definitely link those. So if you're listening, we're gonna have I'm taking copious notes and we're gonna link to all these things.
[00:41:56] swyx: I come with plenty of homework.
[00:41:57] Michael Chan: Yeah, and I think that the the biggest thing, and I think we'll probably release this a little bit early, is that I want people to feel well prepared for, you know, whatever ends up— whatever we end up talking about next week, you know, at React Conf. Because I think a lot of times we put these things, you know, kind of out of sight, out of mind. You know, like I I just have to get my work done. And so I don't want to think about like whatever's on the future. But, you know, this stuff is, you know, stuff is really interesting. And it could very, you know, on, you know, month 1, solve some problems that you've been fighting, you know, beating your head against the wall for for you know a really long time. So, um that's what all of this is in service um to.
[00:42:38] swyx: Yeah, we have one more point, I guess, on the the the talking points that we prepared. Um I think a lot of people uh actually aren't aware that uh a big part of the motivation for Suspense actually comes out of solving streaming server-side rendering uh for React.
[00:42:53] Michael Chan: Yeah.
[00:42:54] swyx: Um I think uh a lot of people— like it's Because because the marketing uh is very much on developer experience on writing uh async fetching API, um I think I think uh people lose sight of the fact that um the uh Facebook or or or React in general is trying to solve this idea that you have to do a double pass for uh server-side rendering for React, um which which can make it slow. Um and then and then the idea that you have to render the whole thing before you send it over. Um so yeah the the concept of streaming server-side rendering is that you're sending bits of HTML and that's rendering as it comes in through the browser, which by the way is how HTML works. Um and and and when when we use React, especially when we use React as a client-side rendering solution, we lose all of that, right? We have to pull in the HTML, um and then we pull in the JavaScript and then we render. Uh and that's obviously a very, very long time to interactive, time to first paint. Um and we want to push as much of that back to uh as possible to um to just render something that shows up and works uh and and works on on screen and then hydrate that as as things come along. Um and so so I I I I think any discussion of Suspense is not complete uh without talking about uh Andrew Clark's demos of streaming server-side rendering. Um that's something that Sebastian has has directly pointed out as, hey, we need that on facebook.com as well. Um and so—
[00:44:18] Michael Chan: Yeah.
[00:44:18] swyx: Um it it these are also— like there are valid criticisms of web performance and and React, right? Like this is a a big part of um you know some some web performance critics uh of of what React does. I think that and and I think they're they're they're exploring all these uh innovative solutions uh because like we we all want the same thing and uh I think we we we want the we want to keep the the authoring experience and the ecosystem that we have built up around around all of this um and then deliver uh better solutions that than the platform naturally gives us. And so and so uh streaming uh uh server-side rendering isn't something that is publicly talked about, probably won't be uh released anytime soon, but um is a big motivation for the API design as well. So you you start to see,
[00:45:01] Michael Chan: yeah,
[00:45:01] swyx: um like why you want all these things in uh inside the React tree, um so that uh the server-side renderer can actually decide for you.
[00:45:09] Michael Chan: Yeah, and I think that's something that's fun. I I mean, if you if you go spelunking at all in the React codebase, you definitely see, you know, stubs for these types of tests where it's like, hey, how are we going to handle, you know, suspense, you know, resolution on, you know, streaming server-side rendering. And it's— and so, yeah, I definitely recommend following along with that. But I I also hope to see like a lot of innovation on that. And I think it'll be interesting to see how the rewrite of Facebook.com plays into that. Do you think that that's, I mean, do you think that's gonna have a good showing at this year's conference?
[00:45:47] swyx: Yeah. Um, so this, uh, Ashley and I, I forget who the other person is, Ashley and Frank, um, from Facebook actually gave this talk at F8. Um,
[00:45:56] Michael Chan: oh,
[00:45:56] swyx: and that was, yeah. Um, and, and that was one of, that was a very, actually the, the more interesting part is Relay because they, they show capability, like Relay is kind of like the uncool kid on the, on the GraphQL block. Uh, Apollo is like all about the marketing and has, has hired really awesome people, uh but Relay does really innovative things. And and uh for a long time, they they were like, they seemed like they were going the way of Flow. Um and uh not to diss not to dunk on Flow, but Flow Flow solved different problems. But but but Relay showed actually really innovative use cases that Apollo just doesn't have. Um and and so, um I think I think that that will be re uh updated, refreshed, uh and and directed towards a more specialized audience. Because F8 is a more generalized, like general developer audience, whereas here they can just go go hog on like React and Relay. Um and so so I think I think yeah it's it's definitely gonna show through in terms of like the stuff that they have used in production. And I think they're at like 110,000-120,000 uh React components in Facebook right now.
[00:46:57] Michael Chan: Holy cow.
[00:46:57] swyx: Yeah, I've been I've been tracking. Uh I used to have this Twitter thread of like, oh, it's 30,000, it's 40,000. Eventually everything in the world will be React components. Um and and then Skynet.
[00:47:11] Michael Chan: It's like a universal paperclip. You ever play that game?
[00:47:15] swyx: Yeah, yeah, yeah.
[00:47:16] Michael Chan: Um so now I am I'm not too too familiar with Relay, but um do you feel like there's gonna be more like first-class tie-ins between like Relay and React that would make it a more attractive solution for someone who has a React codebase with a GraphQL backend?
[00:47:33] swyx: Ooh, that's an interesting question. Um, I I actually, I don't like the word first class uh when it comes to Relay. I think that React has of will have and has and always will have a far wider audience and reach and applicability than than Relay.
[00:47:50] Michael Chan: Sure, sure.
[00:47:51] swyx: So Relay will always be designed around React. Um, the the only advantage that Relay has is that they sit they sit next to each other. So, and they have the same manager.
[00:47:59] Michael Chan: Sorry, I might have said that backwards. I mean, like, do you think uh Relay Relay is gonna have some like first-class affordances for React given how closely tied they are together. Where where um you know like Apollo is is kind of more like generalized across like frameworks. Um do you do you do you suspect that maybe Relay might get closer to React?
[00:48:18] swyx: Uh I mean, obviously, you know, to the extent that they they are they work together, um they have a very natural information flow. But React actually makes a lot of effort uh to work with with uh Apollo, and I I think they're working with urql as well, um on you know just any anyone anyone that is building a significant GraphQL layer. Yep. So I wouldn't worry too much. Uh Ben Neumann, who who is on the Apollo team, um I think used to be on the React team or or on on in somewhere in that org. Um so I you know I think uh they they are they're very familiar with each other and and I think I think uh it's in it's in React's incentive to not play favorites when it comes to um key information. Uh obviously there's there's there's always like you know informal information spreading when you sit next to each other and you share the same you share the same manager. Uh that's that that is there is something new that that happened over the past year that uh React got a new uh team manager. And um I've never met Yuji, uh but uh we'll we'll see her on stage at uh for the first time at React Conf.
[00:49:21] Michael Chan: Awesome, awesome. It'll be cool to cool to cool to meet her. Um, so, there's one component that we haven't talked about, which was new to me, kind of spelunking through the source, uh, which was Suspense.List. And uh, I I don't think we've talked about it yet. But uh, my understanding is is that this component is a way of coordinating uh, kind of child Suspense components, one the ones that might resolve at at very different times. Um, and you had mentioned it uh pretty early on, but it has like a a a prop API called uh revealOrder. And uh you can reveal things together, uh forwards. So effectively, uh top to bottom or left to right, uh or backwards, which would be the the reverse, like right to left or bottom to top.
[00:50:08] swyx: Um, that's exactly that's exactly everything I know as well.
[00:50:13] Michael Chan: Okay.
[00:50:14] swyx: But uh but you you have you have some you have linked some uh demos which uh basically when you refresh it, you see exactly what you're talking about. When you see a uh like think of think about a feed of different events and maybe they all load at different times. But you can fire off their requests and um regardless of what order in which the the async requests resolve, they at least appear in some controllable order. Uh and again, because you're you're just like declaring all these in as as children of a Suspense uh component. Um you don't necessarily have fine-grained control uh except for this one declarative thing that says together forwards and backwards.
[00:50:48] Michael Chan: Yeah, yeah. And this is something that you can play with today. It's it's uh in 16.10 under uh unstable flag. So, it's unstable uh was it Suspense list. And um was it I'm I'm probably gonna butcher the name, but uh Eddie Kuro has um some really cool examples, which I I wanted to bring this component up so that we could link them and you could see uh how these things work together. Because they're like, you know, it's it's it's actually really cool to see to see these different options. Like options that we would have had to like kind of like create by hand before.
[00:51:18] swyx: Manually code, yeah. I actually, I don't know, in terms of like UX design, I don't know when a a backwards uh reveal might might make sense. Not really. Like maybe a chat, right? Like I guess maybe you're when you're rendering a chat and you don't really care about scrolling up the the chat history. You just want to render right to the bottom. Like that's the most important thing. You want to get that on the screen as fast as you can.
[00:51:38] Michael Chan: That seems like the perfect example. I mean, I I had been struggling to find one as well, but that seems like exactly what you're looking for.
[00:51:44] swyx: I just I just answered my own question. I mean, you know, so Facebook does own WhatsApp, so I guess they're they might they might have used it. Uh there's there's another API I think you didn't cover in in these in these demos, the tail um prop. Um so SuspenseList has a reveal order prop and then there's also a tail prop. Uh and you can see from the test that I don't- there's like a hidden hidden flag and a collapse flag. It just controls uh what you do with the tail. Um I haven't actually tried it. I haven't seen a demo of it. Um but it seems pretty intuitive that it just controls what the tail does.
[00:52:17] Michael Chan: Oh, interesting. Very interesting.
[00:52:19] swyx: Um and then and then there's some there's some weird edge cases when you nest a SuspenseList inside of a SuspenseList. Um because that's what you have to do when you when you write a library, when you are a maintainer of a library. Everything like that. So, uh, if you— uh, you know, I definitely recommend checking out that PR for the thinking behind uh the Tail API because there's some nasty nuances when you have when you mix a non-suspense component with Suspense, um, and then you nest the SuspenseList.
[00:52:46] Michael Chan: Yeah, those tests are very interesting. Definitely a fascinating read, uh, that that whole uh the the test for SuspenseList. Um, let's see. So, yeah. So, I think I think we covered all of the things. Oh, sorry. With regard to SuspenseList, if you don't use SuspenseList, you can still render all your your Suspense components. And the default is basically just whatever's ready first renders, right?
[00:53:08] swyx: Um, siblings render together. And then, um, yeah, I mean, right up to the Suspense boundary, siblings will render together. But this-
[00:53:16] Michael Chan: Okay, gotcha.
[00:53:17] swyx: Yeah, like Suspense, a Suspense boundary um controls everything inside of that Suspense boundary. SuspenseList controls Suspense boundary.
[00:53:25] Michael Chan: Gotcha. Okay.
[00:53:26] swyx: That's as much as I can tell.
[00:53:28] Michael Chan: It's still all uh it's all still all pretty new to me.
[00:53:32] swyx: Yeah.
[00:53:32] Michael Chan: Um, so, I think I think that's that's it. What are you most excited about this this next week? Are you are you gonna be there at React Conf? Or are you gonna be watching on the livestream?
[00:53:42] swyx: I I'm not there, uh first of all, because I didn't get a ticket. And they they didn't give me a ticket. Uh but I I I was also— uh I didn't even apply to speak because I'm I'm also I'm already speaking at React Advanced. That's in London. Oh, cool. I had a- probably the best talk I've ever done at JSConf Asia is this talk about writing hooks from scratch. And so that was a general JS audience and I had to like introduce React a little bit and what hooks are and all that. So at a React advanced conference, I can do away with all that and so just go straight into cloning React and then talking a little bit about React Fiber
[00:54:20] Michael Chan: Awesome.
[00:54:21] swyx: A lot of people, like the whole question is about like what do we use React for? And a lot of people will talk about JSX, will talk about the superficial things that you can actually clone in like 30 lines of code. And really what we're using, and I used to say, this was my this was the theme of my React Rally talk last year, I used to say that you use React because of the scheduler. And it turns out that they like you know open source and and stripped out the scheduler right away. So I'm like, all right, what do we use React for? React for? And it's really like the reconciler, the event system, like the the stuff that is like very gnarly and no one no one thinks about. Um so I think when you choose to use React, you should figure out like why why you use it because this like you know that that really gets you to answer core questions like why does Preact um have the same API as React and is a tenth of the size? Um and like you know what what's the trade-off there? I think I think the more you sort of dig into that, the more you have a deeper appreciation of of what React really is and why you use it.
[00:55:22] Michael Chan: Now, before before we go, I'm gonna ask you, um, do you think— I know that there's been like a lot of work happening with like— I think it's under the React Fire kind of like reworking uh React DOM, uh kind of making event components versus like, you know, on on click. And there's a bunch of work kind of happening under the scenes. Do you think that we'll see anything like that at uh at React Conf, or do you think those things are gonna remain under the hood, kind of in like uh R&D phase for a little bit longer?
[00:55:53] swyx: Yeah, I think I think all those things will be R&D. Um, it's it's definitely doesn't seem anywhere as as ready. Um, so, for example, one of the one of the reasons I know that useDeferredValue and useTransition will be uh talked about as as part of the Suspense launch is because um I started talking about them together with another hook called useEvent, which is added as part of the React Flare experiment. And the the React core team came in and and only said that only denied the useEvent hook. They they they only marked they only marked out the useEvent hook as like, no, we won't be releasing that. So so therefore, by by process of elimination, the other two must must be uh pretty final. Um so the yeah, I mean um I I honestly think that uh you know uh it seems like JSX is is due for a refresh. Um that's that's what the React Fire um projects I guess is about. Uh you know there's some superficial things like deprecating className and just using class. Um
[00:56:54] Michael Chan: sure.
[00:56:54] swyx: Which shows how much like probably uh what you know wasn't that strong of an argument that like you know the whole reason we weren't using class is because it's a reserved keyword in JavaScript. But It doesn't seem that strong anymore as an argument. Um anyway, uh there's there's a bunch of sort of ergonomic and and actual performance gains uh to be to become to to be done out of this rewrite. Uh and it seems like it's low-hanging fruit after uh you know the the reconciler rewrite. So uh it seems like they're pursuing this. It doesn't seem like it's any time soon. I'm actually more keen on this other thesis that I'm pursuing, which is, um yeah, it's it so. So there's Fyre and Flare and like I don't know what other uh F F you know code name keywords, um but there's this there's there's a lot more tie-in with uh React Native than before, right? Like you see you saw Fast Refresh, um and Dan Abramov has been spending the past 2 uh 2, 3 months uh working on React Native and I'm like, what are you doing? Go back to go back to your day job. Um and it's uh and and and it's it's not true, I mean it's it's uh you know. That's where that's where they needed help. Um, but it's obviously going to come for uh for React Web as well. Um, and and so um it seems like there's this convergence of React Native and and React uh in in in small ways. Uh so for example, they hired Nicolas Gallagher, uh who created React Native Web, onto the React Core team. I think that's a big sign that uh there's something uh you know going on where they they start caring a lot more. Uh Rick Hanlon from- Rick Hanlon from the React Native team gave a talk on the untouchable web at React Finland. Um, so the the React Native people are coming over to the web. The the the web people are you know are are being hired from the React Native uh side of of things. There seems like there's a lot of convergence. Um, the the the extremely strong view of this is that um in 2 to 3 years, React DOM will look a lot more like React Native Web. Even if it's not a direct port. I don't think that this is a- I think this is a very controversial thesis because that means you're stepping away from an HTML analogy. Like when you write JSX, it looks like HTML and it looks more semantic. And when you start using things like view, text from React Native, that's no longer HTML, that's just like this arbitrary XML tree that you're writing. So I so I I expect that I expect that uh to be a very, very long involved uh evolution of of of discussion as as you know for for React to to achieve its sort of overall vision as um a a universal UI language that can be uh learned once and written everywhere. Um I think I think that's that's something that they have to sort of uh unify. Uh okay, I I I you know this is like a I I've gone on for a while. I'm curious to to hear what you think, but I just want to I just want people to to go check out Recanv. Talk on the untouchable web, because it really hints at-
[00:59:53] Michael Chan: Yeah.
[00:59:53] swyx: What, like, mobile web is, is, is more dominant than desktop web, right? So like people experience mobile web more than they experience desktop web. And we got to pay attention to the user experience over there. And he talks about the holes that they experience and why they might want better APIs for the mobile web.
[01:00:13] Michael Chan: Yeah. I mean, I'm happy that you brought that up because I totally agree. I think that the It seems like early on there was this, hey, we, you know, this was like 5, 6 years ago that they announced like React uh Native. And it kind of felt like this, like this this thing that would be, I guess, developed in tandem or in pair with like React. And it's taken a long time to actually get that to be true, right? Like they were very much separate projects for a very long time. And it feels like not only, you know, are they like you know, kind of properly dependent on each other. But there's a lot of like cross-pollination of ideas and um kind of thinking together. And like people, like you said, who are working, who have been like, you know, into React Native as a platform, um like Nicolas Gallagher, um and his ideas of kind of abstracting the web platform using the React Native uh primitives. Um all that stuff really seems to be like there's communication happening there. And it's gonna be really exciting to see maybe like, you know, a few years down the road, like this actual- you know, I think that they- they- that- what was the idea? Like learn once, write anywhere? Is that kind of- and that derived from-
[01:01:29] swyx: Java.
[01:01:29] Michael Chan: From Java. Well, from from the prevailing idea before that, which was that you could like kind of uh write something and run anywhere, right? Like they had this like response to like like write once, run anywhere, which didn't really like actually seem to work at the time. But it seems like we might might be coming back to a place where we, you know, get the the proper primitives that like React Native actually informs React in such a way that we are writing uh in a way that is platform agnostic by default. And uh I mean, that's-
[01:02:00] swyx: I have I have a I have a hot take on this.
[01:02:02] Michael Chan: That's that's far down the road. But you know.
[01:02:04] swyx: The team won't agree with this. But uh actually, We were sold on "don't once, write anywhere," and what we what we actually are ending up with is "write once, run anywhere." It's it's like this yeah I had this like Trojan horse meme where it's like it's like here's the Trojan horse, it's "don't once, write anywhere," and then what you actually get is "write once, run anywhere." You just had to
[01:02:26] Michael Chan: wait for it.
[01:02:27] swyx: I'll tell you the tell. I'll tell you the tell. It's when people boast about code reuse. Because what is code reuse other than write once, run anywhere. Uh and so we we have I I I have people on the React Reddit all the time talking about like, yeah, when I use React Native Web, I have 90% plus code reuse.
[01:02:42] Michael Chan: Yeah.
[01:02:43] swyx: What is that apart from write once, run anywhere? So, uh like whatever it is, like it's it it definitely is the right solution, especially for for teams that can't, like the whole thing about Airbnb stepping away from React Native is because they have the resources to to hire entire teams of iOS and Android engineers. And of course you can move better and faster with those teams. But you're not Airbnb. So absolutely use the same codebase for Android and React Native, sorry, Android and iOS and web. Like, yeah.
[01:03:16] Michael Chan: Yeah.
[01:03:17] swyx: So I call this, I actually wrote a blog post about this, I call this the singularity, where at some point React Native for web might be a better way to write things than React DOM. And it may not be Nicolas Gallagher's version, it may be a completely reinvented version. But sure, uh he's at he's at a very good spot to to write it. And I think one of the big wins, and this is uh I mean you work closely with Michael Jackson, uh and I got this idea from Michael Jackson, where uh the idea is that you can build in better accessibility primitives, especially because uh React can analyze your your tree structure and assign, for example, like sequential headings.
[01:03:53] Michael Chan: Interesting.
[01:03:54] swyx: Um
[01:03:55] Michael Chan: yeah
[01:03:55] swyx: and and and bake in things like, all right, um you know, a href target no open, no referrer, you know, that kind of like security basics. Um, I'm I'm like I'm like blanking on what else, but uh there is there is work uh done by Dominic from the React core team on focus scopes as well, where you can we can trap focuses, especially within modals and stuff like that. Um, these are all things that uh uh you know are done in user land, uh but don't really have a a good API around it, and therefore it's hard to do and people always get it wrong. So. So, um, I think that's a key motivation that um when you when you when you have control, more control over uh what you write and and and the and the library to interpret that as uh the reactive language, um you can actually get uh better defaults um through uh interpreting this. So, that's-
[01:04:42] Michael Chan: Nice. Well, I I I'm excited for that. I'm I'm excited for that eventual world and I I I agree with you. I'm convinced. I've seen, I've seen, I mean, seeing uh with at React Native for web, I think that really just kind of, you know, blew my mind as to like what was possible, you know, if, you know, in the future. And I think that that, you know, just like all of Nicholas's stuff, he's just kind of like ahead of his time. And I feel like, you know, if if we could get to a place like that, it'd be it'd be awesome. Really awesome.
[01:05:09] swyx: Absolutely.
[01:05:10] Michael Chan: Yeah. Cool. So, um, I mean, we've been over an hour. So I don't want to take up any more time. It's just so much fun to talk with you about this stuff. Do you have anything else that you want to you want to address before we before we leave?
[01:05:23] swyx: I think there's a there's so I've been playing around with Svelte a bit. I think uh there is some there's some talk of like compilers are the new frameworks. And this is some this is a thesis actually from Tom Dale, um who's big in the Ember community. I think there there is a lot more uh focus on like pushing things to to build uh to build times. Uh that's why Gatsby is is helping to optimize a bunch of things. Uh Next.js has a bunch of of optimizations that are being introduced by the Chrome team. Um, and and so there was there was a little bit of excitement around prepack, um, which which uh I think Dominic was also working on, um, around optimizing React. It doesn't seem like that's something that's a high, high, high priority. Like this is even longer term than than everything else that we've discussed. Yeah. But uh there is there is some focus on React's uh compiling React. And and and and what we can get out of that. So I don't know, I I think I'm I'm I'm also optimistic towards uh people talking about that as well because I think that's that's one area that React is uh not focusing on and and and uh frameworks like Angular, Svelte, and Ember are all doing it.
[01:06:28] Michael Chan: Yeah, yeah. We actually did an episode a long time ago, like uh 18, where we talked with uh Nikolaj Tilman uh about prepacks and um kind of what it could could, you know, what it could mean for React. Um, but again, I mean, it was like, you know, I I suspect that it's probably still in the phase uh that it was, which is just very much research. Like they they have a couple cool, like, you know, proofs of concept. But in terms of, you know, how that would actually apply to something as complex as like a React application, uh just kind of like not not quite uh not quite proven yet.
[01:07:02] swyx: That's that's all that's all I got.
[01:07:03] Michael Chan: But what's the Nice. What's the- now just for uh kind of uh thoroughness, uh you mentioned Svelte, but Ember also has— um what's what's Ember's um kind of compiled-
[01:07:13] swyx: Glimmer.
[01:07:14] Michael Chan: Um Glimmer, that's right. So, we have Svelte and Glimmer.
[01:07:19] swyx: Angular Ivy as well.
[01:07:20] Michael Chan: Angular Ivy.
[01:07:22] swyx: You should just interview all these all these people. I'm I'm sure-
[01:07:26] Michael Chan: I know.
[01:07:27] swyx: You know what would be amazing is to have Angular and Ember people on the React podcast and like like what's going on there and like what what what do they think that we don't we don't talk about, you know?
[01:07:36] Michael Chan: Oh, oh, I oh yeah, I'm I want it. I want it. Yeah, yeah, yeah. I I I want it. It's I I I'm here for it. Um, yeah. So, I think uh I think that's it. I think we should probably just say once again, you know, like this is just us hanging out, talking about stuff that we think is cool and like want to see. We don't speak for anybody but our two nerdy selves just hanging out on this call.
[01:08:00] swyx: There go those crazy React Asians again. Yammering on.
[01:08:04] Michael Chan: Yeah, so that's all this is. We're just, you know, two two uh two two dudes reading pull requests and tests.
[01:08:14] swyx: You got to get a better hobby.
[01:08:17] Michael Chan: Awesome. Well, hey, Swyx, thanks so much for uh for being uh being here with me. Uh I I I enjoy these chats every time we have them.
[01:08:27] swyx: Thanks, Michael. Cool. Cheers.
[01:08:28] Michael Chan: Cheers. Thanks for listening. Before you go today, I want to give you 15% off of React Day Berlin. This conference is always a hit and they have a terrific speaker roster this year. Go to reactday.berlin, another fun domain, uh and use the promo SPECFM. Or just find this episode's show notes at reactpodcast.com/69. Nice. And click our link, which will automatically apply that discount code for you. Thanks to our great sponsors, G2i and Infinite Red. G2i is a hiring platform for remote developers devoted exclusively to React and React Native. Check out G2i at g2i.co and get matched with React and React Native roles that are fully remote at companies who are serious about quality and G2i, we vet, you get hired. It's that simple. Bring your ideas to life with React Native. Hire the industry experts at Infinite Red. Visit reactpodcast.infinite.red and get 2 tickets to next year's Chain React Conf when you start a new project. Meet the team and see why they are the ones to take your React Native app the distance. This episode of React Podcast was edited It was edited by Mikael Delport. It was produced by Mikael Delport and Sarah Jackson. You can find React Podcast on Speck, a network to help designers and developers level up. Visit speck.fm to find other shows that will take you further in your career. Help us out by reviewing this show on iTunes. Your reviews help the show grow and help us ensure great guests and awesome content week to week. To join the discuss- To join the discussion, visit reactpodcast.com/chat or follow us on Twitter @reactpodcast. I'm @chantastic. To stay out of the discussion but get updates, visit reactpodcast.com/news and sign up for emails. Thanks so much for giving us your attention. We'll be in your ears again next week.
chantastic.fm