Skip to content
PodSubs
ShowsPeopleGuestsJobsNewsEvents
More
BlogPodCred
Menu
ShowsPeopleGuestsJobsNewsEventsBlogPodCredNetworksSign in
Join nowSign in
  • Shows
  • People
  • Jobs
  • News
  • More
    • Guests
    • Events
    • Blog
    • PodCred
    • Networks
    Join nowSign in

Code & Curiosity by Maximilian Schwarzmüller

Code & Curiosity by Maximilian Schwarzmüller artwork

What's going on with React?

Dec 17, 202512 minAudio
  • Apple Podcasts

We had multiple React-related severe security vulnerabilities within a few weeks. Did React get too complex? Is the client-server complexity eating into security?

Audio and video play straight from the show's own hosting. PodSubs stores and serves no media.

Transcript

From the show. Tap a time to play from there.

React clearly has seen better days. I mean, not from a usage point of view. It's getting more usage than ever before. Of course, also because it's the default JavaScript AI. Build some project with AI and you'll get React and Next.js. I've talked about this in another episode. But it's seen easier days with less hate and heat. I mean, over the last couple of weeks, major vulnerabilities. One of them being so severe that

attackers could execute code on your server if you were affected. By the way, make sure you patch your React If you're using Next.js or some other framework components, you're likely affected. But the amount of hate is really a bit staggering to me because there are things you can criticize. But then there are also some things that are really not that bad that some people make them seem. But let's dive a bit deeper. What are we talking about?

It was actually in 2020, so yeah, five years ago, uh, almost to the day, uh, five years ago, that React server components were introduced. What's the idea behind React server components? Well, the idea back then and, and still today was and is that you could render React components on a server, but not in the sense of server-side initially and then that's it. But instead that you would also render them for page updates. If a user interacts with a page,

clicks a link, you would render the new page on the well and send that to the client, and also react to a couple of other things. And at the same time, of course, don't just have static HTML, but a single page application kind of the server, but then fully interactive on the client. In order to make this work, they had to invent their own protocol because the idea was not to render HTML and send that HTML, but instead to exchange a payload from to client and vice versa that does describe the current state of

application, the component tree, and that therefore is more complex than just raw data sent through JSON or raw HTML because you need both the page structure and the state, the data. So that's React server components. Due to this complexity, it took some time for them to take off. Remember, they were initially announced in 2020 and then the first time you could actually really use them was in 2022, so two years later with the release of Next.js 13,

which gave us a beta version of the app router, which, of course, nowadays is the standard router if you're building a new Next.js application. For a very long time, you could actually only use React server components in Next.js and that brought its own problems and some fair share of criticism because it felt like React was kind of Next.js. There was such a close connection feel like you could reuse React without Next.js, at least if you wanted cutting edge features like React server

components. It's also not just React server We also have like the other side, server actions, which in the end allow you to submit a form and behind the scenes an HTTP request would be sent to your server, would be handled there, and you would get back an updated payload that updates your React application. So an updated React server component if you wanna call it like this. That's in a nutshell how it works blend backend and frontend code, server-side and client-side code because you have React on both ends and there

is this magic going on where you have components being rendered on the server, there's special kind of payloads being sent back and forth, server actions. And of course, the vulnerabilities I talked about, these are related to React server components specifically to that protocol, the React Flight Protocol as it's called, for communicating between client and server. However, what's really important is that it's not per se that blending of client-side

and server-side code that's a problem here. Only indirectly, if you will, because of course that protocol was invented to be able to blend these two ends. But when it comes to being able to fetch some data on the server and then render a dynamic page based on that, that's in the end how PHP always worked, right? So back when we built very primitive, simple PHP apps, you could reach out to a database back some HTML code based on that. And now with React and React server

components, it's kind of the same. You have that mixture of client-side and server-side, but of course it's a bit more than that because unlike PHP, with React the idea is that you have a fully interactive client-side application powered by JavaScript and that's why this extra protocol because it doesn't stop after this initial transfer from server to client. But from time to time I see this image pop up, which is from an early presentation of and I believe its support in Next.js.

And this slide is often used by people to criticize React and how insecure it is and I want to be very clear, and you probably heard it before, nothing about this code on this slide is insecure. This SQL statement runs on the server there is no SQL injection going on here. This SQL tagged literal here makes sure that all the input is sanitized. So this is secure even though it might look a bit weird and it might look like we're reaching out SQL database in our React component, we're not actually doing

that. This is a server action step which is triggered on the server, the magic is that this function, this server action is invoked on your behalf invisibly behind the scenes because there is an HTTP request sent to the server to then, well invoke the code there. And that again is using that special payload, the React Flight Protocol. With all that out of the way what I will say though with all these features, with React server components and server actions and with that client and server-side

mixture that's going on here, React has gotten more complex. And especially for less experienced developers it can definitely be harder to tell which code runs where. Now I will say you will get errors if you put code that can only run on the server into your client-side code or vice versa. You can't really mess this up, at least not that easily I'd say. But of course I understand that this can be

confusing. It's definitely an easier mental model have an API, a REST API, a GraphQL API, whatever, which is a standalone application and then you have your detached client-side single page application and they communicate through HTTP requests which you explicitly send with help of the Fetch API or with help of a library like React Query. This is definitely the easier mental model.But there is a reason why React server components

were invented, if you wanna call it like this. They were invented because, of course, with that other mental model, with that other approach, you always had two applications. You had your backend server, you had your client side server or application. That, I would say, gets a bit easier with React server components because we have just one full stack application here. Kind of the idea behind Next.js even before React server components. Next.js kind of made sure that this API, plus

single page application, that this thing was wired up properly and you could deploy it as one application even before React server components. But that shows us that there was this need, this demand for having full stack applications that kind of blend both because that is what Next.js did even before React server components. Because even before that, you had special functions where you would put your codes that would be fetched to prepopulate your server side rendered, uh, components on the server.

We had that before React server components. React server components came because there was a need for this kind of application. If you don't like them, if you don't want them, and there that, if you don't like that mental model of blending server and client-side code somehow, you don't have to. You can still build your standalone single page applications with React, with any router or any libraries of your choice.

Could be React Router, could be TanStack Router, but that doesn't really make sense because Next.js is really more of a full stack framework. And then you can have your detached API, API, your GraphQL API, whatever it is. You can still do that if that makes more sense for you, if you prefer this approach. And I will agree that React got more complex over all these years with Suspense, React server components, Server Actions, all the optimization hooks that

exist in there, the React compiler, which is there to make optimizing simpler again. That can all feel very overwhelming. I mean, I remember a time where React was pretty straightforward. You had your class-based components for components, your function components for stateless, It was relatively easy and simple. You had other problems back then, uh, for example, that you had to switch between class-based and functional components, refactor your components if you suddenly needed state, so that

great. But yeah, it was probably a simpler mental model. I totally get this point, and it is fair to criticize this. It's also important to point out though there are alternatives. Of course you might not have them if you're in a company that uses React, like many companies probably do, but if you're not, you've got alternatives. If you are somewhere where you're forced to use React, it's probably worth noting that despite all this complexity, and again, there are good

reasons why things got more complex, React typically does still save you lots of headaches because it is built to do many optimizations for you. Some complexity comes out of that urge to, to optimize stuff for you or to load and render parts of the page efficiently, and these are ultimately benefits you get out of React or out of using React, at least potentially. Nonetheless, there definitely are things to criticize about React, and

I too hope that we won't see more and more and more complexity being layered on top of React. But at the same time, all these discussions about how insecure it is because it blends client server side code like this, I really can't hear them anymore. Because, in my opinion, that is not really the main problem here and definitely not the root of these vulnerabilities.

Open the transcript file

Hosts and Guests

Nobody is credited on this episode yet.

Credit the people on this episode

Be the first to rate this episode

More episodes

All episodes
  1. We will have to accept AI-generated content

    Oct 15, 202612 minAudio

    I think we'll have to get used to (and accept) AI generated content. Not to slop though.

    • Apple Podcasts

    Credit the people on this episode

  2. Is software dead?

    Oct 13, 202612 minAudio

    There's a lot of talk about software being dead. Unsurprisingly, it's complicated.

    • Apple Podcasts

    Credit the people on this episode

  3. GPT 6 Astra - Good Beyond 3D?

    Sep 9, 20268 minAudio

    GPT 6 Astra was released. It's a good model, I have to say. Especially for 3D work it seems to be a real game changer. But due to all the hype, you may be disappointed...

    • Apple Podcasts

    Credit the people on this episode

  4. You may ignore Omarchy but not its impact

    Aug 26, 20268 minAudio

    Omarchy got a lot of hype and visibility recently. But even if you don't care or don't use it, you shouldn't ignore it.

    • Apple Podcasts

    Credit the people on this episode

  5. SvelteKit 3, Solid 2 - Do they matter anymore?

    Aug 18, 202614 minAudio

    We're not going back to the JS framework wars. BUT new frameworks and framework versions are important. For a different reason now!

    • Apple Podcasts

    Credit the people on this episode